Android中通過程式碼修改bitmap的寬高
阿新 • • 發佈:2019-02-01
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 = newMatrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的圖片. Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newBitmap; }