AndroidImageView设置图片原理

关于图片和ImageView,其实有更多可以介绍的,比如在解析图片前获得图片的宽高,用来做图片适配;比如等比例缩小图片,以减小内存占用;比如图片旋转效果等等。

创新互联专业网站设计制作、网站设计,集网站策划、网站设计、网站制作于一体,网站seo、网站优化、网站营销、软文发布平台等专业人才根据搜索规律编程设计,让网站在运行后,在搜索中有好的表现,专业设计制作为您带来效益的网站!让网站建设为您创造效益。

第一个问题和第二个问题:

               BitmapFactory.Options options = new BitmapFactory.Options();
/*
* If set to true, the decoder will return null (no bitmap), but the
* out... fields will still be set, allowing the caller to query the
* bitmap without having to allocate the memory for its pixels.
*/
options.inJustDecodeBounds = true;
String url=Environment.getExternalStorageDirectory().getPath() +"/test.jpg";//sdcard/test.jpg
BitmapFactory.decodeFile(url,options);
int outWidth=options.outWidth;//获得图片的宽
int outHeight=options.outHeight;//获得图片的高
int width=100;//放图片组件的宽
int height=100;//放图片组件的高
double shink=outHeight*outWidth/width/height;//缩小的比例
options.inSampleSize=(int) Math.sqrt(shink);//inSampleSize设置,则缩小比例即它的平方,如2则比例为1/4。

Bitmap bitmap=BitmapFactory.decodeFile(url, options);//此值就是我们所需要的值


网站栏目:AndroidImageView设置图片原理
标题来源:http://hxwzsj.com/article/jessed.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都网站建设 成都网站设计 成都定制网站建设 成都网站建设 成都网站建设 H5网站制作 重庆网站制作 外贸营销网站建设 四川成都网站建设 网站制作 成都h5网站建设 高端定制网站设计 网站设计制作报价 网站建设公司 成都商城网站建设 移动手机网站制作 高端网站设计 网站建设方案 手机网站制作 手机网站制作 成都品牌网站建设 重庆网站建设