今天來說說 Bitmap 的一些處理方式
如果有想要放大、縮小、旋轉角度的朋友看過來
這裡為大家介紹一個物件 Matrix 
它可以為我們達成心願喔!!!

 

以下為使用範例
看完之後我們應該就會使用了

// 使用 Matrix 物件
Matrix matrix = new Matrix();

int width = bitmap.getWidth();
int height = bitmap.getHeight();

//想要的大小
int newWidth = 360;
int newHeight = 520;

//計算比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;

// 設定 Matrix 物件,設定 x,y 向的縮放比例 
matrix.postScale(scaleWidth, scaleHeight);

// 設定 Matrix 物件,設定順時針旋轉90度
matrix.postRotate(90.0F);

/**
 * creatBitmp的參數依序如下:
 * 原圖資源
 * 第一個pixel點的x座標
 * 第一個pixel點的y座標
 * 圖片的總pixel行
 * 圖片的總pixel列
 * Matrix 的設定
 * 是否filter圖片
 */
newBitmapSize = Bitmap.createBitmap(bitmap, 0, 0,
        bitmap.getWidth(), bitmap.getHeight(),
        matrix, true);








參考資料:
https://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap, int, int, int, int, android.graphics.Matrix, boolean)


arrow
arrow
    全站熱搜

    顏澤偉 發表在 痞客邦 留言(0) 人氣()