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://bzwzjz.com/article/jessed.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 品牌网站建设 网站设计 成都网站制作 重庆企业网站建设 营销型网站建设 app网站建设 成都网站制作 企业手机网站建设 网站建设公司 成都做网站建设公司 成都网站设计 成都响应式网站建设 梓潼网站设计 高端网站设计 成都网站设计 外贸营销网站建设 高端品牌网站建设 成都品牌网站设计 成都网站设计 成都网站建设 成都网站建设公司 成都网站建设