[英]Unnecessary scaled image
When I want to draw image using following functions I always get exactly 3 times bigger image than it's source has. 当我想使用以下功能绘制图像时,我总是得到的图像正好是其源图像的三倍。 So if I want to have displayed size 1000x1000 I have to resize source image to 335x335 and then it will be uncutted.
因此,如果我要显示的尺寸为1000x1000,则必须将源图像的尺寸调整为335x335,然后才将其剪切。
screen = new Screen(BitmapFactory.decodeResource(getResources(), R.drawable.rose1), 40, 200, 1000, 1000, 1);
Screen contructor in Screen.java: 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);
}
But when I use 但是当我使用
image[i] = Bitmap.createScaledBitmap(spritesheet, width, height, true);
everything is OK, but what if I want to add animated object? 一切都很好,但是如果我想添加动画对象怎么办?
Finally I found the solution. 终于我找到了解决方案。 Should set the inScaled to false.
应将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);
As here it was also described: How to resize Bitmaps the optimal way in Android? 如此处所述, 如何在Android中以最佳方式调整位图的大小?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.