Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> Android bitmap圖片處理

Android bitmap圖片處理

編輯:高級開發

 //放大縮小圖片

  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;

  }

  //將Drawable轉化為Bitmap

  public static Bitmap drawableToBitmap(Drawable drawable){

  int width = drawable.getIntrinsicWidth();

  int height = drawable.getIntrinsicHeight();

  Bitmap bitmap = Bitmap.createBitmap(width, height,

  drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888

  : Bitmap.Config.RGB_565);

  Canvas canvas = new Canvas(bitmap);

  drawable.setBounds(0,0,width,height);

  drawable.draw(canvas);

  return bitmap;

  }

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved