BitmapFactory.Options options=new BitmapFactory.Options();//创建权利                //先不计算内存                options.inJustDecodeBounds=true;                BitmapFactory.decodeResource(getResources(),R.mipmap.bitmap,options);                //调用Options方法来获取图片宽高                int outHeight = options.outHeight;                int outWidth = options.outWidth;                Log.d(TAG,"outHeight == >"+outHeight);                Log.d(TAG,"outWidth == >"+outWidth);                //拿控件的尺寸                int measuredHeight = result_image.getMeasuredHeight();                int measuredWidth = result_image.getMeasuredWidth();                Log.d(TAG,"measureHeight ==>"+measuredHeight);                Log.d(TAG,"measureWidth ==>"+measuredWidth);                //默认不改变大小                options.inSampleSize=1;                //图片的宽度/控件的宽度                //图片的高度/控件的高度                //取两者间的最小值                if (outHeight>measuredHeight||outWidth>measuredWidth){                    int subHeight = outHeight / measuredHeight;                    int subWidth = outWidth / measuredWidth;                    options.inSampleSize=subHeight>subWidth?subWidth : subHeight;//                }                options.inJustDecodeBounds=false;//可以设置进去了                Log.d(TAG,"options.inSampleSize==>"+options.inSampleSize);                //根据控件大小,动态计算sample值                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.bitmap, options);                result_image.setImageBitmap(bitmap);

更多相关文章

  1. android中TextView嵌套在ScrollView中并自由滚动
  2. Android(安卓)NullPointerException at android.text.BoringLayo
  3. android常用控件
  4. Android(安卓)图片缩放实例详解
  5. Android圆角图片封装类(直接使用)
  6. android旋转图片
  7. android获取图库图片并返回
  8. android WebView 拍照上传图片兼容
  9. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片

随机推荐

  1. Android 之手势识别篇-GestureDetector
  2. Android6.0 设置默认输入法
  3. 【Android UI设计与开发】第14期:顶部标题
  4. android 中TextView设置部分文字背景色和
  5. [置顶] 安卓开发-标签总结
  6. 在android上使用cairo
  7. Android资源文件 - 使用资源存储字符串
  8. 1.1.2 Android的系统框架
  9. android 大小写转换
  10. Android中UI主线程与子线程