当我想使用以下函数绘制图像时,我总是得到比源图像大 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);
关于java - 不必要的缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48357630/