【发布时间】:2011-01-05 11:39:03
【问题描述】:
我大半夜都在为此烦恼,所以也许你们中的一个可以帮我一把。
我发现 C# 中的 GDI+ DrawImage 对于我要渲染的内容来说太慢了,从论坛的外观来看,其他人也一样。
我决定尝试使用 Win32 API 中的 AlphaBlend 或 BitBlt 以获得更好的性能。无论如何,除了一个小细节外,我的图像显示得很好——无论我使用什么图像格式,我都无法让白色背景从我的(透明)图形中消失。
到目前为止,我已经尝试过 BMP 和 PNG 格式,并验证它们在 C# 中加载为 32bppargb 图像。
这是我正在打的电话:
// Draw the tile to the screen.
Win32GraphicsInterop.AlphaBlend(graphicsCanvas, destination.X, destination.Y, this.TileSize, this.TileSize,
this.imageGraphicsPointer, tile.UpperLeftCorner.X, tile.UpperLeftCorner.Y,
this.TileSize, this.TileSize,
new Win32GraphicsInterop.BLENDFUNCTION(Win32GraphicsInterop.AC_SRC_OVER, 0,
Convert.ToByte(opacity * 255),
Win32GraphicsInterop.AC_SRC_ALPHA));
为了记录,AC_SRC_OVER 是 0x00,AC_SRC_ALPHA 是 0x01,这与 MSDN 所说的应该是一致的。
你们中的任何人有解决这个问题的好方法吗,或者知道更好(但仍然很快)的方法吗?
【问题讨论】:
标签: c# graphics winapi gdi+ gdi