相关疑难解决方法(0)

如何渲染透明光标到位图保留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();
    }
Run Code Online (Sandbox Code Playgroud)

不幸的是我无法将透明光标渲染到位图!当我将Cursor直接绘制到窗体画布时,它可以工作,但是当我将Cursor绘制到位图时会出现问题.任何建议都非常感谢.

替代文字

.net c# transparency gdi+ cursor

9
推荐指数
1
解决办法
3968
查看次数

标签 统计

.net ×1

c# ×1

cursor ×1

gdi+ ×1

transparency ×1