public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 设置想要的大小
int newWidth1 = newWidth;
int newHeight1 = newHeight;
// 计算缩放比例
float scaleWidth = ((float) newWidth1) / width;
float scaleHeight = ((float) newHeight1) / height;

// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
true);
if(width != newWidth && height != newHeight){
freeBitmap(bm);
}
return newbm;


}

更多相关文章

  1. Android 实现局部图片滑动指引效果
  2. Android学习教程之九宫格图片展示(13)
  3. Android 7.0调用相机拍照并获取图片路径
  4. 实现Android的图片画廊控件ScrollGalleryView
  5. Android相机相册的调用,图片的存储删除
  6. Android实用图片显示控件photoview
  7. android原生分享图片失败的问题
  8. Android TextView带背景图片和自定义边框

随机推荐

  1. Android面经| 问题归纳
  2. 横竖屏切换时候activity的生命周期 andro
  3. CrystaX NDK - 更强大的Android(安卓)NDK
  4. eclipse android开发环境 bug CDT包含路
  5. Android---2---TextView、Button、EditTe
  6. Android(安卓)上Camera分析
  7. Android(安卓)支持多屏幕机制
  8. Android(安卓)Web development Note
  9. 为Android加入busybox工具
  10. Android(安卓)RelativeLayout 相对布局解