【问题标题】:Disable bitmap filtering on Android Canvas在 Android Canvas 上禁用位图过滤
【发布时间】:2021-03-18 00:03:33
【问题描述】:

我试图在画布上显示简单的像素艺术,但由于抗锯齿、双线性过滤或可能的类似原因,它显示模糊。据我所知,我无法具体识别它。

其他人以前也问过同样的问题,但答案似乎已经过时了。

我目前基本上拥有的东西:

paint = new Paint();
paint.setAntiAlias(false);
paint.setDither(true);
paint.setFilterBitmap(false);
bitmap = BitmapFactory.decodeResource(res, R.drawable.image);
bitmap = Bitmap.createScaledBitmap(bitmap , 320, 320, false);

canvas.drawBitmap(bitmap , 30, 50, paint);

编辑 1

我得出的结论是,它绝对不是抗锯齿,因为它实际上会试图使边界平滑。谁能认出实际发生的事情?

The original image

Screenshot of the original image

The image after getting brutalized by some unidentified filtering

【问题讨论】:

  • 所以想必你找到了这个之前的问题stackoverflow.com/questions/25827549/…。你为什么要setDithering(那种东西不会弄脏一点吗?)?或者,位图是否被拉伸/压扁/不再正确的纵横比?
  • 您是否尝试在真正的 ImageView 之外评估“位图”,但使用断点和 ALT+F8 面板代替? ImageView 通常会缩放 Bitmap,因此通过查看 ImageView 来验证代码的正确性可能是错误的。

标签: java android canvas pixel antialiasing


【解决方案1】:

除了您所做的之外,我还添加了以下代码,它似乎可以工作。

 BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    options.inDensity = options.inTargetDensity ;

    forestBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.forest_bkg, options);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 2017-04-11
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多