I'm trying to get a bitmap copy of the cursor icon by using the Windows API methods GetCursorInfo() and CopyIcon(), and then using System.Drawing.Icon.FromHandle() to capture the bitmap. When I run this in a console application it works fine; however, when running in Unity the Icon.FromHandle() method fails. I've copied different versions of System.Drawing.dll into my assets folder, but haven't found a version that works. Any thoughts on how to make this work, or another way to capture the cursor icon?
CURSORINFO cursorInfo = new CURSORINFO();
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
if (GetCursorInfo(ref cursorInfo))
{
if (cursorInfo.flags == CURSOR_SHOWING)
{
IntPtr cursorHandle = CopyIcon(cursorInfo.hCursor);
Icon ic = Icon.FromHandle(cursorHandle);
Bitmap cursorBitmap = ic.ToBitmap();
}
}
↧