0
我正在調整位圖數組的大小到一定百分比的屏幕(因此在所有設備上看起來都是一樣的)。一些位圖是+ 256kb大小的精靈(爆炸等)。位圖超出範圍錯誤
顯然,一旦位圖轉換了兩次,虛擬機內存不足,位圖僅在android應用程序的開始時進行轉換,但仍然出現錯誤。
任何人都可以告訴我,有沒有更好,更快,更高效的方法來將此代碼作爲位圖返回。
只是出於好奇,是通過引用傳遞的位圖值? (就像對象參數對同一對象使用同一行內存?)。
總之在這裏爲z代碼:
public Bitmap ResizeBitmap(Bitmap bitmap, float s_percentage, int frames, int viewport_width, int viewport_height)
{
float percentage = s_percentage/100.0f;
float scale = viewport_width/100 * percentage;
if(viewport_width < viewport_height)
{
scale = viewport_height/100 * percentage;
}
int newWidth = (int) (bitmap.getWidth() * scale);
int newHeight = (int) (bitmap.getHeight() * scale);
if(newWidth <= 0 || newHeight <= 0)
{
// Extra check, for invalid width/height
Log.e("Function List, Resize Bitmap", "invalid dimension ("+newWidth+"x"+newHeight+")");
return bitmap;
}
//Round up to closet factor of total frames
int rW = (newWidth/frames)+1;
newWidth = rW*frames;
Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);
return newBitmap;
}