图片压缩处理方法
来源:互联网 发布:成都多益网络公司地址 编辑:程序博客网 时间:2024/05/17 03:16
/** * 图片压缩处理(质量法) * * @param image * @return */ private Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 image.compress(Bitmap.CompressFormat.JPEG, 100, baos); int options = 100; // 循环判断如果压缩后图片是否大于100kb,大于继续压缩 while (baos.toByteArray().length / 1024 > 20) { // 重置baos即清空baos baos.reset(); // 每次都减少10 options -= 10; // 这里压缩options%,把压缩后的数据存放到baos中 image.compress(Bitmap.CompressFormat.JPEG, options, baos); } // 把压缩后的数据baos存放到ByteArrayInputStream中 ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); // 把ByteArrayInputStream数据生成图片 Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null); return bitmap; } /** * 图片压缩处理(尺寸法) * */ public Bitmap resizeBitmap(int width, int height, Bitmap bitmap) { // 图片尺寸 int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); // 缩放图片的尺寸 float scaleWidth = (float) width / bitmapWidth; float scaleHeight = (float) height / bitmapHeight; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 产生缩放后的Bitmap对象 Bitmap resizeBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, false); return resizeBitmap; }
0 0
- 图片压缩处理方法
- 图片处理--压缩图片
- 图片压缩处理
- 图片上传压缩处理
- 图片压缩处理
- Java图片压缩处理
- 图片上传压缩处理
- Thumbnailator(图片压缩处理)
- java处理压缩图片
- C#图片压缩处理
- 图片上传压缩处理
- Java图片压缩处理
- java压缩图片处理
- iOS图片压缩处理
- 图片压缩处理
- iOS图片压缩处理
- Android图片压缩处理
- Java图片压缩处理
- iperf使用方法
- 查看oracle数据库全局数据库名和sid
- OpenCV特征点检测匹配图像-----添加包围盒
- cookie/session 转载文章
- 使用帝国cms开发的网站,这些留言反馈的信息是注入吗?
- 图片压缩处理方法
- day17:RDD案例(join、cogroup、reduceByKey、groupByKey, join cogroup
- AutoLayout
- LCD接口分类/DPI/DBI/DSI总结
- 如何解决failed to push some refs to git
- python cls 和 self
- pch 文件的创建
- App半透明指引(第一次进去app的新功能或者版本更新之后使用)
- 1038. Recover the Smallest Number (30)