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://csdahua.cn/article/jessed.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流