1. 程式人生 > >Android中通過程式碼修改bitmap的寬高

Android中通過程式碼修改bitmap的寬高

public Bitmap getNewBitmap(Bitmap bitmap, int newWidth ,int newHeight){
    // 獲得圖片的寬高.
int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    // 計算縮放比例.
float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // 取得想要縮放的matrix引數.
Matrix matrix = new 
Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的圖片. Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newBitmap; }