标签:override UI class orb lease code ret stat private
WPF Cursor类中的两个构造函数:
public Cursor(Stream cursorStream) public Cursor(string cursorFile)
以上的构造函数所使用的的资源均是 ani 或 cur的文件,并不支持图片的方式生成。
/// This class allow you create a Cursor form a Bitmap /// </summary> internal class BitmapCursor : SafeHandle { public override bool IsInvalid { get { return handle == (IntPtr)(-1); } } public static Cursor CreateBmpCursor(Bitmap cursorBitmap) { var c = new BitmapCursor(cursorBitmap); return CursorInteropHelper.Create(c); } protected BitmapCursor(Bitmap cursorBitmap) : base((IntPtr)(-1), true) { handle = cursorBitmap.GetHicon(); } protected override bool ReleaseHandle() { bool result = DestroyIcon(handle); handle = (IntPtr)(-1); return result; } [DllImport("user32")] private static extern bool DestroyIcon(IntPtr hIcon); }
提供的扩展方法:
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; } }
转自:http://www.cnblogs.com/zhouyinhui/archive/2010/05/28/1746502.html
标签:override UI class orb lease code ret stat private
原文地址:https://www.cnblogs.com/runningRain/p/8973986.html