0

ドローアブルフォルダからビットマップを返すために使用する関数があります。(描画可能なDPIフォルダーは使用しません。時間の無駄です)

とにかく、関数はビットマップを取得しますが、ビットマップはビューポートサイズの指定されたパーセンテージとして返されます。

現時点では、指定されたパーセンテージよりも少ない値を返しています。たとえば、ground要素:

パーセンテージは、幅の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;
}
4

1 に答える 1

3
_newWidth = (screen_dimention / 100) * percentage;

整数除算を行っています。

あなたが望むかもしれません

_newWidth = (screen_dimention / 100.0) * percentage;

または、_newWidthが実際に整数に切り捨てられることになっている場合は、

_newWidth = (screen_dimention * percentage) / 100;

後で切り捨てます。

于 2012-06-09T11:31:54.350 に答える