我正在尝试使用画布显示图像.png,但由于某种原因我无法使其工作,图像没有消除锯齿。这使得它在曲线或对角线上全部像素化。
这是我正在使用的代码:
Pixmap button = g.newPixmap("button.png");
@Override
public Pixmap newPixmap(String fileName) {
Config config = Config.ARGB_8888;
Options options = new Options();
options.inPreferredConfig = config;
InputStream in = null;
Bitmap bitmap = null;
try {
in = manager.open(fileName);
bitmap = BitmapFactory.decodeStream(in, null, options);
if (bitmap == null)
throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'");
} catch (IOException e) {
throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return new Pixmap(bitmap);
}
g.drawPixmap(button);
@Override
public void drawPixmap(Pixmap pixmap) {
srcRect = new Rect(0, 0, pixmap.getOriginalWidth(), pixmap.getOriginalHeight());
dstRect = new Rect(pixmap.getX(), pixmap.getY(), pixmap.getX() + pixmap.getVirtualWidth(), pixmap.getY() + pixmap.getVirtualHeight());
canvas.drawBitmap(pixmap.bitmap, srcRect, dstRect, paint);
}
我可能做错了什么?
答案 0 :(得分:0)
尝试:
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
或者:
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);