我正在制作android的像素游戏。我正在使用32x32图像。为了让游戏看起来一样,无论屏幕尺寸如何,我都会动态地放大图像。我的问题是,放大的时候,图像的部分不保持其原有的颜色:完美地放大小位图像素
6个块,32×32最初。正如你所看到的,在黑色边缘之前有一个不需要的阴影线(大概是黑色和红色的平均值)。
这是我使用缩放代码:
public abstract class Drawable {
protected int x;
protected int y;
protected Bitmap image;
Drawable(Bitmap image, int x, int y, float scale) {
this.x = x;
this.y = y;
this.image = Bitmap.createScaledBitmap(image, (int)(image.getWidth()*scale), (int)(image.getHeight()*scale), false);
}
abstract void draw(Canvas canvas);
}
正如你看到的,我不使用过滤器。这会使边缘区域更模糊。是否有另一个过滤器,相比之下,如果在放大时真正使用哪个真正保持图像的清晰度?
编辑:
现在我试过这种方法代替:
scaledRect = new RectF(x, y, x+image.getWidth()*scale, y+image.getHeight()*scale);
paint = new Paint();
paint.setAntiAlias(false);
paint.setDither(false);
paint.setFilterBitmap(false);
而且在绘制调用:
canvas.drawBitmap(this.image, null, scaledRect, paint);
没有成功...
向上扩展位图将有模糊的副作用。也许矢量图形是你正在寻找的。 https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html –
我从来没有见过任何人使用矢量图形制作像素艺术,但我会检查出来。 –