gpt4 book ai didi

java - 不必要的缩放图像

转载 作者:太空宇宙 更新时间:2023-11-04 10:46:32 25 4
gpt4 key购买 nike

当我想使用以下函数绘制图像时,我总是得到比源图像大 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?

关于java - 不必要的缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48357630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com