// 缩放图片
public static Bitmap zoomImg(String img, int newWidth ,int newHeight){
// 图片源
Bitmap bm = BitmapFactory.decodeFile(img);
if(null!=bm){
return zoomImg(bm,newWidth,newHeight);
}
return null;
}

public static Bitmap zoomImg(Context context,String img, int newWidth ,int newHeight){
// 图片源
try {
Bitmap bm = BitmapFactory.decodeStream(context.getAssets()
.open(img));
if (null != bm) {
return zoomImg(bm, newWidth, newHeight);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 缩放图片
public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}

更多相关文章

  1. android 笔记 --- Android-图片透明度处理代码
  2. Android Retrofit2.0 上传单张图片和多张图片
  3. android bitmap图片压缩,打时间水印。
  4. 在Android中调用图片、视频、音频、录音、拍照
  5. Android通过网络URL获取图片并显示
  6. ClipDrawable制作图片渐进效果
  7. Android拍照后图片旋转问题

随机推荐

  1. Android中文文档笔记①
  2. ListView的长按键事件的处理
  3. Android中ActionBar中不显示overflow(就是
  4. Ubuntu环境变量
  5. 常见问题汇总一
  6. Android(安卓)Framework系列之IPC(二)
  7. Android 模糊效果实现
  8. Android 解决Could not find com.android
  9. 基于百度推送android notification的使用
  10. js判断运行平台