Search code examples
androidimagescale

Scaled images show some sort of tiling


in my app I scale an image dynamically to 50% of its original size. When scaled it shows some sort of tiling (look image below). There are square parts of the image that ware brighter than neighbouring tiles that should have the same colour. It is barely noticeable but it is which is not good enough for my app. The size of the square depends on the scaling factor. So at a factor of 75% size the tiles a smaller.

Example:

enter image description here

My drawing code (is called in onDraw of my custom View):

private void drawImage(Bitmap bitmap, float scaling,
        Canvas canvas, float offset)
{

    Matrix p = new Matrix();
    Matrix m = new Matrix();
    Matrix y = new Matrix();
    Matrix o = new Matrix();

    p.setTranslate(-bitmap.getWidth() / 2, -bitmap.getHeight() / 2);

    // translation to views center (minus half height of image
    // so that the bottom of the picture is in the views center.
    y.setTranslate(getWidth() / 2, getHeight() / 2);
    // offset translation.
    o.setTranslate(offset, 0);

    m.setScale(scaling, scaling);
    m.preConcat(p);
    m.postConcat(y);
    m.postConcat(o);

    // draw image
    canvas.drawBitmap(bitmap, m, null);
}

Does anyone know how to prevent this tiling?


Solution

  • Have you tried canvas.drawBitmap(bitmap, m, new Paint(Paint.FILTER_BITMAP_FLAG)) as seen here.