预压缩处理图片 options.inJustDecodeBounds = true
来源:互联网 发布:梦龙网络计划编制软件 编辑:程序博客网 时间:2024/05/16 01:35
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//只读取图片,不加载到内存中 BitmapFactory.decodeFile(file, options); options.inSampleSize=computeSampleSize(options, -1, 512*512);//返回合适的inSampleSize值 options.inJustDecodeBounds = false;//加载到内存中 bitmap = BitmapFactory.decodeFile(file, options);
computeSampleSize 方法
public static int computeSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { int initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels); int roundedSize; if (initialSize <= 8) { roundedSize = 1; while (roundedSize < initialSize) { roundedSize <<= 1; } } else { roundedSize = (initialSize + 7) / 8 * 8; } return roundedSize; } public static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; } if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
0 0
- 预压缩处理图片 options.inJustDecodeBounds = true
- 深入安卓大图片处理机制,本地及网络图片不加载到内存预压缩
- java Gzip 预压缩
- 图片缩放 inJustDecodeBounds inSampleSize
- 对BitmapFactory.Options.inJustDecodeBounds的理解
- android 图片压缩之 injustdecodebounds
- 图片缩放 inJustDecodeBounds inSampleSize matrix
- BitmapFactory.Options处理图片的缩放
- nginx 预压缩(gzip)静态文件
- linux下处理图片时需加上参数“-Djava.awt.headless=true”
- linux下处理图片时需加上参数“-Djava.awt.headless=true”
- linux下处理图片时需加上参数“-Djava.awt.headless=true”
- Android获取图片指定大小的缩略图--inJustDecodeBounds的使用
- var options = options || {};
- contenteditable="true"的div事件处理
- BitmapFactory.Options 图片解析
- BitmapFactory.Options压缩图片
- inJustDecodeBounds解析
- Android如何在activity中控制屏幕点亮与关闭
- 浅谈C/C++ 开发Excel插件之操作excel
- 1078 - Integer Divisibility
- 关于小米手机及一些使用相册去选取图片的手机的一些问题
- php checkbox 取值详细说明
- 预压缩处理图片 options.inJustDecodeBounds = true
- zabbix agent类型的所有key 值
- Swift 图片轮播图
- iOS - NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- 奇异值和特征值
- 【九度】题目1065:输出梯形
- 【svn】svn的diff命令用法详解
- 安卓版本更新后进入引导界面
- leetcode 40. Combination Sum II 解题报告