不必要的缩放图像

Unnecessary scaled image

当我想使用以下函数绘制图像时,我总是得到比源图像大 3 倍的图像。因此,如果我想显示 1000x1000 的尺寸,我必须将源图像的尺寸调整为 335x335,然后它将被未剪切。

screen = new Screen(BitmapFactory.decodeResource(getResources(), R.drawable.rose1), 40, 200, 1000, 1000, 1);

Screen.java 中的屏幕构造函数:

public Screen (Bitmap res, int xPos, int yPos, int w, int h, int numFrames){
    super.x = xPos;
    super.y = yPos;
    height = h;
    width = w;
    Bitmap [] image = new Bitmap[numFrames];
    spritesheet = res;

    for (int i = 0; i<image.length; i++){
        image[i] = Bitmap.createBitmap(spritesheet, i*width, 0, width, height);
        //image[i] = Bitmap.createScaledBitmap(spritesheet, width, height, true);
    }

    animation.setFrames(image);
    animation.setDelay(10);
}

但是当我使用

 image[i] = Bitmap.createScaledBitmap(spritesheet, width, height, true);

一切正常,但如果我想添加动画对象怎么办?

我终于找到了解决办法。 应将 inScaled 设置为 false。

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
screen = new Screen(BitmapFactory.decodeResource(getResources(), R.drawable.rain2, options), 40*WIDTH_X/1080, 200*HEIGHT_Y/1920, 1000,1000, 1);

这里也有这样的描述: How to resize Bitmaps the optimal way in Android?