Android:指定分辨率和清晰度的图片压缩方法源码
来源:互联网 发布:编程资料百度云 编辑:程序博客网 时间:2024/06/06 00:16
http://www.wizzer.cn/?p=1792
- public void transImage(String fromFile, String toFile, int width, int height, int quality)
- {
- try
- {
- Bitmap bitmap = BitmapFactory.decodeFile(fromFile);
- 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);
- // save file
- File myCaptureFile = new File(toFile);
- FileOutputStream out = new FileOutputStream(myCaptureFile);
- if(resizeBitmap.compress(Bitmap.CompressFormat.JPEG, quality, out)){
- out.flush();
- out.close();
- }
- if(!bitmap.isRecycled()){
- bitmap.recycle();//记得释放资源,否则会内存溢出
- }
- if(!resizeBitmap.isRecycled()){
- resizeBitmap.recycle();
- }
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
0 0
- Android:指定分辨率和清晰度的图片压缩方法源码
- Android:指定分辨率和清晰度的图片压缩方法源码
- Android:指定分辨率和清晰度的图片压缩方法源码
- 码率,帧率,分辨率和清晰度的关系
- 分辨率和清晰度的区别关系
- 码率,帧率,分辨率和清晰度的关系
- 码率,帧率,分辨率和清晰度的关系
- 清晰度、分辨率和锐度的关系
- android按分辨率压缩图片
- 三种Android图片压缩方法 压缩到指定大小
- 三种Android图片压缩方法 压缩到指定大小
- 图片压缩大小清晰度测试
- 【转】成像的清晰度、分辨率和锐度
- 谈谈码率,帧率,分辨率和清晰度的关系
- 谈谈码率,帧率,分辨率和清晰度的关系
- android 图片压缩的方法
- android压缩图片的方法
- android 图片压缩的方法
- 【JZOJ4784】【NOIP2016提高A组模拟9.15】Map
- oracle中的between使用
- Java字符串分割
- windows本地安装redis单机和集群配置
- Kinect 骨骼追踪数据处理
- Android:指定分辨率和清晰度的图片压缩方法源码
- Redis:主从复制
- The next step
- Meteor中文博客转载
- 机器学习中的算法-支持向量机(SVM)基础
- JSPatch Platform平台的简单使用
- 【NOIP2016提高A组模拟9.21】矩阵
- convolutional sparse coding codes
- 【龙印】用M665和M666给三角洲3D打印机调平