/** * resize Bitmap *  * @param bitmap * @param newWidth * @return */public static Bitmap resizeBitmap(Bitmap bitmap, int newWidth) {if (bitmap == null)return null;int w = bitmap.getWidth();int h = bitmap.getHeight();Log.e("Jarvis", w + "~" + h);float temp = ((float) h) / ((float) w);int newHeight = (int) (newWidth * temp);float scaleWidth = ((float) newWidth) / w;float scaleHeight = ((float) newHeight) / h;Matrix matrix = new Matrix();matrix.postScale(scaleWidth, scaleHeight);Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix,true);if (!bitmap.isRecycled()) {bitmap.recycle();}return resizedBitmap;}
/** * 放大缩小图片 *  * @param bitmap * @param w * @param h * @return */public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {int width = bitmap.getWidth();int height = bitmap.getHeight();Matrix matrix = new Matrix();float scaleWidht = ((float) w / width);float scaleHeight = ((float) h / height);matrix.postScale(scaleWidht, scaleHeight);Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,matrix, true);return newbmp;}

更多相关文章

  1. Android截屏及图片解析
  2. Android 利用animation-list自定义progressbar动画出现图片平铺
  3. android-RadioButton背景使用图片
  4. 图片中的毕加索【Picasso】
  5. Android实现ListView异步加载图片

随机推荐

  1. android 手风琴
  2. android 判断屏幕是否关闭
  3. android使用5.0的toolbar,自定义布局参考
  4. Android(安卓)XML pull解析
  5. android在Service,BroadCast onReceiver(
  6. Android(安卓)OTA升级详细流程分析(non-AB
  7. Android(安卓)中的建造者模式
  8. android mvn project
  9. android eclipse错误集合
  10. Android(安卓)camera HAL四个callback