/**  * 按照比例放大或者缩小图片**/public static Bitmap scaleImage(Bitmap oldImage, int newW, int newH) {return scaleImage(oldImage,newW,  newH,false);}public static Bitmap scaleImage(Bitmap oldImage, int newW, int newH,boolean isRecycleOld) {if (oldImage == null)return null;int oldWidth = oldImage.getWidth();int oldHeight = oldImage.getHeight();Matrix matrix = new Matrix();matrix.postScale((float) newW / oldWidth, (float) newH / oldHeight);Bitmap resizedBitmap = Bitmap.createBitmap(oldImage, 0, 0, oldWidth,oldHeight, matrix, true);if(isRecycleOld){oldImage.recycle();}return resizedBitmap;}
/** * bitmap to byte[] *  * @param bitmap * @return */public static byte[] flattenBitmap(Bitmap bitmap) {if(bitmap ==null) return null;int size = bitmap.getWidth() * bitmap.getHeight() * 4;ByteArrayOutputStream out = new ByteArrayOutputStream(size);try {bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);out.flush();out.close();return out.toByteArray();} catch (IOException e) {return null;}}/** * byte[] to bitmap *  * @param bytes * @return */public static Bitmap bytesToBitmap(byte[] bytes) {if (bytes == null)return null;return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);}

更多相关文章

  1. Android常用到得方法积累
  2. Android(安卓)压缩工具类
  3. Android中的GalleryView实例演示-周末福利有美女图
  4. ViewPager用法(一)图片+原点+循环播放
  5. Android(安卓)设置TextView滑动滚动条和滑动效果
  6. RelativeLayout布局属性详解
  7. Android两种 旋转Bitmap方法
  8. Android多点触摸缩放图片-android学习之旅(四)
  9. android中比较两张图片的相似度

随机推荐

  1. add 'tools:replace="android:value"' to
  2. Android开发:关于Android冷启动优化(从3.63
  3. android studio从Eclipse迁移
  4. android Application学习之二
  5. android Animation 动画效果介绍
  6. Android利用android:indeterminateDrawab
  7. android 字符串数组资源
  8. Android Long SMS
  9. android 之activity生命周期(转载)
  10. Android多点触控---Matrix图片随意的放大