二次采样 OOM的克星
来源:互联网 发布:python idle打开闪退 编辑:程序博客网 时间:2024/04/30 12:57
//找控件 ImageView iv = (ImageView) findViewById(R.id.iv); //加载图片 没有对图片进行处理 /*Bitmap bitmap = BitmapFactory.decodeFile("/mnt/shared/Image/big.JPG"); iv.setImageBitmap(bitmap);*/ //使用二次采样对图片进行压缩 BitmapFactory.Options options = new BitmapFactory.Options(); //只加载图片的宽高 不加载图片像素 第一次采样 options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile("/mnt/shared/Image/big.JPG",options); //获取图片宽高 int outWidth = options.outWidth; int outHeight = options.outHeight; //获取手机屏幕的宽高 Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); int scaleX = outWidth/width; int scaleY = outHeight/height; int scale = 0; //对比大的作为缩放比例 scale = scaleX>scaleY?scaleX:scaleY; //第二次采样 加载图片的像素 options.inJustDecodeBounds = false; //设置图片缩放比例 options.inSampleSize = scale; Bitmap bitmap1 = BitmapFactory.decodeFile("/mnt/shared/Image/big.JPG",options); iv.setImageBitmap(bitmap1);
阅读全文
0 0
- 二次采样 OOM的克星
- 图片二次采样有效防止因图片引起的OOM
- 图片的二次采样
- 图片的二次采样
- Bitmap的二次采样
- bitmap的二次采样
- 图片的二次采样
- Bitmap的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- 图片的二次采样
- A-B Problem
- 数组中次数超过一半的数
- 携程旅行网 :合并数组的的中位数
- 数塔问题
- Java面试题四
- 二次采样 OOM的克星
- js 闭包常见的两种情况的简单解析
- Git学习笔记
- 异步提交表单的应用---异步上传图片
- Java面试题五
- 操作系统学习笔记
- 文章标题
- Python GUI布局尺寸适配
- 字符串空格的处理