I load png resources using BitmapFactory.decodeResource and then draw them on Canvas using drawBitmap() .
I draw the different layers one at a time so that the transparent objects cover what they were supposed to, but when I have alpha levels in my png that are above 0, they seem to be ignored. Places where alpha is 0 are not displayed correctly, but where alpha is less than 255, instead of blending the color with the existing color on that pixel, it just draws it without any alpha blending.
How to draw a bitmap on Canvas with proper blending based on alpha channel of source images? The following are snippets of code:
BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Config.ARGB_8888; ... decorationTextures[1] = new TextureStatic(BitmapFactory.decodeResource(resources, R.drawable.ice_1, opt)); decorationTextures[2] = new TextureStatic(BitmapFactory.decodeResource(resources, R.drawable.ice_2, opt)); ... if(mTexture != null && mInPlay) { if(mZone != null) canvas.drawBitmap(mTexture.getBitmap(), mScreenX + mZone.getXOffset(), mScreenY + mZone.getYOffset(), null); else canvas.drawBitmap(mTexture.getBitmap(), mScreenX, mScreenY, null); }
source share