图片压缩算法,保证图片不失真
来源:互联网 发布:微交易系统源码破解版 编辑:程序博客网 时间:2024/04/28 18:49
在各种项目中,都难免遇到图片的上传和下载,然而,图片的上传,需要压缩后再上传才是明智之举;然后,压缩图片可能会导致图片的失真等等问题,在这里,我将在工作中使用的比较好的图片压缩方法,分享给大家。
public static Bitmap revitionImage(String path) throws IOException {
BufferedInputStream in = new BufferedInputStream(new FileInputStream( new File(path)));
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(in, null, options); int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1;
int reqHeight = 800; int reqWidth = 480;
if (height > reqHeight || width > reqHeight) { final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } options.inJustDecodeBounds = false; options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeFile(path, options);
<span style="white-space: pre;"></span> ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos); byte[] b = baos.toByteArray(); Bitmap result = BitmapFactory.decodeByteArray(b, 0, b.length); if (baos != null) baos.close(); if (in != null) in.close(); return result; }
0 0
- 图片压缩算法,保证图片不失真
- 图片压缩不失真
- 图片极致压缩,不失真
- android图片压缩不失真
- VB压缩图片(不失真)
- 笔记:Android不失真压缩图片
- Android实现图片压缩并且不失真
- android图片压缩不失真实战
- PS压缩图片文件大小,不失真!!!
- StretchBlt()压缩图片失真
- 不失真缩放图片
- PS如何不失真压缩图片【网站上应用】
- Android高效压缩图片不失真的方法总结
- iOS 根据屏幕宽高等比压缩图片 不失真
- Get技能---如何压缩图片文件大小不失真
- 解决StretchBlt()压缩图片失真
- 解决StretchBlt()压缩图片失真
- PS图片压缩教程,教你快速压缩jpg图片文件的大小而又不失真!
- LCD 显示相关的参数说明
- 无外网状态下,批量安装windows服务器补丁
- spark学习资料
- MTK_手机驱动培训资料
- vs2010调试C++程序时提示 无法启动文件“....exe”系统找不到指定文件
- 图片压缩算法,保证图片不失真
- pyqt4制作透明无边框窗体
- 两条有趣的机试试题
- MTK报错与分析
- js验证表单大全
- WinForm递归获取树形菜单及右键菜单
- HDU:4249 A Famous Equation(数位DP)
- LCD 驱动中参数说明
- 编写 EL 自定义函数 的方法