【发布时间】:2011-04-12 05:14:05
【问题描述】:
我正在使用BitmapFactory.decodeResource 加载png 资源,然后使用drawBitmap() 在Canvas 上绘制它们。
我一次绘制一个不同的层,以便透明对象应该遮挡它们应该遮挡的部分,但是当我的 png 中的 alpha 级别高于 0 时,它们似乎会被忽略。不渲染 alpha 为 0 的地方,这是正确的,但是在 alpha 小于 255 的地方,它不会将颜色与该像素处的现有颜色混合,它只是在没有任何 alpha 混合的情况下绘制它。
如何在Canvas 上绘制位图,并根据源图像的 Alpha 通道进行适当混合?相关代码sn-ps如下:
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);
}
【问题讨论】:
-
你找到解决这个问题的方法了吗?