我用下面的代码来呈现透明图标:如何将透明光标渲染为保存Alpha通道的位图?
private void button1_Click(object sender, EventArgs e)
{
// using LoadCursorFromFile from user32.dll
var cursor = NativeMethods.LoadCustomCursor(@"d:\Temp\Cursors\Cursors\aero_busy.ani");
// cursor -> bitmap
Bitmap bitmap = new Bitmap(48, 48, PixelFormat.Format32bppArgb);
Graphics gBitmap = Graphics.FromImage(bitmap);
cursor.DrawStretched(gBitmap, new Rectangle(0, 0, 32, 32));
// 1. Draw bitmap on a form canvas
Graphics gForm = Graphics.FromHwnd(this.Handle);
gForm.DrawImage(bitmap, 50, 50);
// 2. Draw cursor directly to a form canvas
cursor.Draw(gForm, new Rectangle(100, 50, 32, 32));
cursor.Dispose();
}
可惜我无法呈现透明光标为位图!它在我直接将Cursor绘制到窗体画布时起作用,但当我将Cursor绘制到位图时出现问题。 任何意见是高度赞赏。
呀,GDI +已经知道问题绘制图标时,可以保留Alpha通道。也许有人知道解决方法,但我怀疑最好的方法是使用GDI代替。 – 2010-12-15 16:06:58
嗯......很可惜,因为我想留在托管代码中。你知道吗,如果Windows 7仍然使用GDI来渲染透明度游标? – 2010-12-15 16:27:26
看起来很熟悉。此处需要署名。如果你注意到这一点,你可能会得到更好的答案。 – 2010-12-15 16:40:02