簡體   English   中英

在不縮放圖像的情況下增加 bitmap 大小

[英]Increase bitmap size without scaling image

我想在我的 Android 應用程序中增加 Bitmap 的大小。

這聽起來像是一個非常簡單的操作,但我無法在任何地方找到如何操作。 這是一張圖片來說明我在這里想要實現的目標: 我想要的兩個位圖

基本上,我想創建一個新的 bitmap,它的寬度與原來的相同,但高度更大。 (新)額外像素的背景可以是黑色、白色或透明的。

我怎樣才能做到這一點?

像這樣的一些應該這樣做。

// Create a Canvas to draw to
Canvas bitmapCanvas = new Canvas();
// Create a Bitmap to back the Canvas of the new size
Bitmap bitmap = Bitmap.createBitmap(X, Z, Bitmap.Config.ARGB_8888);
bitmapCanvas.setBitmap(bitmap);

// Calculate the new position of bitmap
// Middle of new Z dimension minus half the original height to centre it.
int newY = (Z / 2) - (Y / 2);

// Draw original bitmap to new location
Paint paint = new Paint();
paint.setAntiAlias(true);
bitmapCanvas.drawBitmap(origBitmap, 0, newY, paint);


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM