按照指定的寬高(或指定比例)來重新設定bitmap
阿新 • • 發佈:2019-02-02
//把傳進來的bitmap物件轉換為寬度為x,長度為y的bitmap物件 public static Bitmap big(Bitmap b, float x, float y) { int w = b.getWidth(); int h = b.getHeight(); float sx = (float) x / w; float sy = (float) y / h; Matrix matrix = new Matrix(); //也可以按兩者之間最大的比例來設定放大比例,這樣不會是圖片壓縮 // float bigerS = Math.max(sx,sy);// matrix.postScale(bigerS,bigerS); matrix.postScale(sx, sy); // 長和寬放大縮小的比例 Bitmap resizeBmp = Bitmap.createBitmap(b, 0, 0, w, h, matrix, true); return resizeBmp; }