Android ImageView设置图片原理

发布时间:2020-10-17 21:41:11 作者:Android_Robot
来源:网络 阅读:685

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

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

               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);//此值就是我们所需要的值


推荐阅读:
  1. Android开发 - ImageView加载Base64编码的图片
  2. Android实现ViewPager无限循环效果(一)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

having without memory

上一篇:Java基于分治算法实现的棋盘覆盖问题示例

下一篇:C#类继承中构造函数的执行序列示例详解

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》