Two constructors in the WPF cursor class:
Public Cursor (Stream cursorstream) Public Cursor (string cursorfile)
The resources used by the above constructors are either ANI or cur files and do not support the way images are generated.
///This class allow you to create a Cursor form a Bitmap/// </summary> Internal classBitmapcursor:safehandle { Public Override BOOLIsinvalid {Get { returnHandle = = (INTPTR) (-1); } } Public StaticCursor createbmpcursor (Bitmap cursorbitmap) {varc =Newbitmapcursor (CURSORBITMAP); returncursorinterophelper.create (c); } protectedbitmapcursor (Bitmap cursorbitmap):Base((INTPTR) (-1),true) {Handle=Cursorbitmap.gethicon (); } protected Override BOOLReleaseHandle () {BOOLresult =DestroyIcon (handle); Handle= (INTPTR) (-1); returnresult; } [DllImport ("User32")] Private Static extern BOOLDestroyIcon (IntPtr hicon); }
Extension methods provided:
public static Bitmap Bitmapsourcetobitmap (this BitmapSource source) { using (var stream = new MemoryStream ()) { var e = new Bmpbitmapencoder (); E.frames.add (bitmapframe.create (source)); E.save (stream); var bmp = new Bitmap (stream); return bmp; } }
Transferred from: http://www.cnblogs.com/zhouyinhui/archive/2010/05/28/1746502.html
WPF Creating a custom mouse cursor pointer