下面的代碼定義我的位圖:將縮放的位圖繪製到畫布上?
Resources res = context.getResources();
mBackground = BitmapFactory.decodeResource(res,
R.drawable.bg2);
//scale bitmap
int h = 800; // height in pixels
int w = 480; // width in pixels
Bitmap scaled = Bitmap.createScaledBitmap(mBackground, w, h, true); // Make sure w and h are in the correct order
...而下面的代碼被用於執行/繪製(未縮放的位圖):
c.drawBitmap(mBackground, 0, 0, null);
我的問題是,我怎麼可能將其設置爲繪製以「位圖縮放」形式返回的縮放位圖,而不是原始圖片?
你的答案對我有效,但在參數中從寬度和高度減去1後,在顯示的位圖的右側和底部顯示一行(從背景中的另一個位圖),刪除-1工作正常。 – akshay7692
我知道這是一個較舊的帖子。但對於Android 7.0+,在分屏模式下,您可能無法依賴完整的顯示寬度/高度。因此,對於使用此解決方案的任何人,您應該牢記這一點。 – MCLLC
會以這種方式繪製位圖很慢嗎? – Amos