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 fileFile 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();}}

更多相关文章

  1. Android webView 支持缩放及自适应屏幕
  2. Android设备各种使用尺寸整理
  3. Android图片缩放、圆角处理以及倒影特效代码
  4. Android中的webView控件实现网页缩放
  5. 通过OpenGL ES混合模式缩放视频缓冲区-Android 4游戏编程高级篇
  6. Android 屏幕尺寸和分辨率的适配
  7. Android如何解决显示屏尺寸适配问题

随机推荐

  1. AsyncTask源码分析
  2. Android(安卓)task和affinity讲解
  3. Android Google Map V2 备忘
  4. Could not GET 'https://dl.google.com/d
  5. Android——全屏显示的两种方式
  6. android缩放动画的两种实现方法
  7. AIDL的实例,看一看结构
  8. 如何选好Android开发书籍和教程[总结]
  9. Delphi XE5 Android 运行黑屏卡死的解决
  10. Android客户端与java服务端AES加解密