0
如何將Matrix
轉換爲Bitmap
/Drawable
?如何將矩陣轉換爲位圖/可繪製?
如何將Matrix
轉換爲Bitmap
/Drawable
?如何將矩陣轉換爲位圖/可繪製?
其實我不明白你的問題。但是,如果你想調整一個圖像,然後這個或許對你會有所幫助:
Bitmap bmap = BitmapFactory.decodeStream(getClass().getResourceAsStream("Your image path"));
int oldHeight= ..
int newHeight = ..
int oldWidth = ..
int newWidth = ..
scaleheight= newHeight/oldHeight
scaleWidth = newWidth/oldWidth
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap and set it back
Bitmap resizedBatteryImage = Bitmap.createBitmap(bmap, 0, 0,oldWidth, oldHeight, matrix, true);
試試這個代碼
ImageView image = (ImageView) findViewById(R.id.test_image);
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.test);
Matrix mat = new Matrix();
Bitmap bMapimage = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true);
bMapimage的結果有位圖圖像。還有一件事,請記住使用位圖時的內存管理,bitmapfactory ...使用此嘗試後,嘗試將其設置爲空。
感謝farhana haque。 –