Blurry pixel paint on scaled canvas drawBitmap on Samsung devices

雨燕双飞 提交于 2021-01-28 05:20:36

问题


Some users encountered blurry pixels issue on Samsung devices. I don't have any Samsung device to check, but there is no problems with phones I have.

I can't understand what is different on Samsung and why there is no issue with other devices! It will be very nice if someone could help me to understand!

Thank you!

How it looks on samsung

My code:

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.save();
    canvas.translate(imagePosition.getX(), imagePosition.getY());
    canvas.scale(mScaleFactor, mScaleFactor);

    boolean hasBackground = backgroundImage != null;

    if (hasBackground) {

        canvas.drawBitmap(backgroundImage, 0, 0, backgroundPaint);

        if (currentMode != ColoringModeEnum.NONE && activity.getAppSettings().highlightActiveSquares) {
            canvas.drawBitmap(hintBitmap, 0, 0, paint);
        }
    }

    canvas.drawBitmap(coloringBitmap, 0, 0, paint);
    canvas.restore();
}


private final Paint paint = new Paint();

回答1:


Your bitmap looks filtered. To fix this, you can call:

backgroundPaint.setFilterBitmap(false)

The question then becomes, why does it only appear to do this on Samsung devices? Obviously, app programmers must be able to predict which state their Paint objects are in, otherwise their apps will break (as yours did).

So, I ran this past a few devices in my test lab. It appears that the default isFilterBitmap() setting (FILTER_BITMAP_FLAG) changed on API 29, although I'm unable to find it in the source code (if anyone can find it, or has more insight, please add a comment, or suggest an edit!)

Device                API level     isFilterBitmap() default
---------------------------------------------------------------------
Pixel 3 XL            29            true
Pixel 2 XL emulator   29            true
Pixel 2 XL emulator   28            false
Pixel 2 emulator      26            false
Samsung S6            25            false
Samsung S4            21            false
Droid RAZR            16            false


来源:https://stackoverflow.com/questions/60239696/blurry-pixel-paint-on-scaled-canvas-drawbitmap-on-samsung-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!