我有一个函数用于从可绘制文件夹中返回位图。(我不使用drawable DPI文件夹,浪费时间)
无论如何,该函数检索位图,位图作为视口大小的指定百分比返回。
目前它返回的百分比小于指定的百分比,例如接地元素:
百分比应该是宽度的 100%,即 480 像素。显然这应该是 480 但它返回 400?我必须在这里遗漏一些简单的数学运算,或者代码如下:(我也应该使用 createscaledbitmap 吗?)
public Bitmap getBitmapSized(String name, int percentage, int screen_dimention, int frames, int rows)
{
_tempInt = _context.getResources().getIdentifier(name, "drawable", _context.getPackageName());
_tempbitmap = (BitmapFactory.decodeResource(_context.getResources(), _tempInt, _BM_options));
_bmWidth = _tempbitmap.getWidth() / frames;
_bmHeight = _tempbitmap.getHeight() / rows;
_newWidth = (screen_dimention / 100) * percentage;
_newHeight = (_newWidth / _bmWidth) * _bmHeight;
//Round up to closet factor of total frames (Stops juddering within animation)
_newWidth = _newWidth * frames;
//Output the created item
Log.w("Screen Width: ", Integer.toString(screen_dimention));
Log.w(name, "Item");
Log.w(Integer.toString((int)_newWidth), "new width");
Log.w(Integer.toString((int)_newHeight), "new height");
//Create new item and recycle bitmap
Bitmap newBitmap = Bitmap.createScaledBitmap(_tempbitmap, (int)_newWidth, (int)_newHeight, false);
_tempbitmap.recycle();
System.gc();
return newBitmap;
}