Suppose I have a hexagon:
If I resize this to use it in my application which contains a grid of hexagons:
// ...
bgPaint = new Paint();
bgPaint.setAntiAlias(true);
bgPaint.setDither(true);
// ...
Bitmap coloredBackground = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
// ...
canvas.drawBitmap(coloredBackground, null, getAsRect(), bgPaint);
I get this:
getAsRect()
returns a Rect
object I use for drawing. What I want to achieve is to get rid of those transparent pixels at the edges. I think I'm doing something wrong but I could not find where so far. Do you have any idea how can I solve this problem?
I tried experimenting with dither and antialias but nothing changed.
3 suggestions:
Try this: Turn off the system's scaling when you decode the resource by setting BitmapFactory.Options.inScaled to false:
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg, options);
The inScaled
flag should be turned off if you need a non-scaled version of the bitmap.
Then scale your bitmap with Bitmap.createScaledBitmap(...)
.
Another possible reason is that your tile's diagonal black lines contain different shades of grey:
This is a close up of your tile:
It's anti-aliased before it's resized. Any pixels not totally black may show up as lighter color in the resized lines. You could change your lines lines to be completely black (0xFF000000) and do anti-alias only after the resizing.
Another solution to this problem is to design your tile like so:
which avoids the problem of drawing two anti-aliased diagonal lines next to each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With