canvas.drawBitmap()仅在0时表示alpha层

我用
BitmapFactory.decodeResource
加载png资源,然后使用
drawBitmap()
Canvas
上绘制它们。 我一次绘制一个不同的图层,这样透明的对象就会遮挡它们的内容,但是当我的png中的alpha级别高于0时,它们似乎会被忽略。 alpha为0的地方不会被渲染,这是正确的,但是当alpha小于255而不是将颜色与该像素处的现有颜色混合时,它只绘制它而根本没有任何alpha混合。 如何根据源图像的alpha通道正确混合在
Canvas
上绘制位图?相关代码片段如下:
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);
}
    
已邀请:
您是否尝试更改
SurfaceView
(如果使用的话)和/或
Window
的格式以匹配您正在使用的位图的格式(
ARGB_8888
)?这可能会阻止您获得真正的透明效果,在任何情况下,您都应该尝试匹配窗口/位图格式以获得更好的性能/质量。 尝试
Window.setFormat(PixelFormat.RGBA_8888);
SurfaceHolder.setFormat(PixelFormat.RGBA_8888;
设置像素格式。     

要回复问题请先登录注册