I have a .cur file path ("%SystemRoot%\cursors\aero_arrow.cur"
) witch I want to display in an image control. So I need to convert Cursor to ImageSource. I tried both CursorConverter and ImageSourceConverter but had no luck. I also tried creating Graphics from the cursor and then converting it to Bitmap, But that didn't work either.
This thread says:
it is complicated to convert Cursor to Icon direcetly because Cursor doesn't expose the imagesource it use.
and
If you really want to bind an image to cursor, there is an approach you might want to try.
Since WindowForm is capable of drawing the cursor, we can use WindowForm to draw cursor on a bitmap. After that we could find a way to copy that bitmap to something WPF support.
Now the funny thing is that I can't create a new instance of System.Windows.Forms.Cursor
with neither the file path nor the stream since It throws the following exception:
System.Runtime.InteropServices.COMException (0x800A01E1):
Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
So can anybody tell me the best way to convert System.Windows.Input.Cursor
to ImageSource
?
And what about .ani cursors? If I remember correctly System.Windows.Input.Cursor
does not support animated cursors, So how can I show them to the user? Converting them to gif then using the 3d party gif libraries?