1
我想旋轉,然後使用android.graphics.Matrix縮放圖像。代碼如下:在Android中使用矩陣旋轉和縮放圖像
int width = bmp1.getWidth();
int height = bmp1.getHeight();
int smallerVal = (height > width) ? width : height;
int n = 0;
while (smallerVal > 1)
{
smallerVal = smallerVal >> 1;
n++;
}
int pow2 = (int) Math.pow(2, n);
float scaleWidth = ((float) AppBase.width)/(float)pow2;
float scaleHeight = ((float) AppBase.height)/(float)pow2;
Matrix matrix = new Matrix();
matrix.postRotate(90);
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bmp2 = Bitmap.createBitmap(bmp1, 0, 0, pow2, pow2, matrix, true);
pow2是爲了應用紋理而得到平方冪的圖像。 bmp2原來有-1作爲高度和寬度,即一個無效的圖像。我錯過了什麼嗎?
感謝,
Rajath
你的代碼對我來說真的很有價值。我想要在seekbar上旋轉圖像,然後縮放它以適應imageview的高度寬度。你有什麼建議嗎? – 2013-09-19 12:56:59