#region 图片转换为BitmapSource ToBitmapSource
[DllImport("gdi32")]
static extern int DeleteObject(IntPtr o);
/// <summary>
/// 图片转换为BitmapSource
/// </summary>
/// <param name="bitmap">图片对象System.Drawing.Bitmap</param>
/// <returns>BitmapSource</returns>
public static BitmapSource ToBitmapSource(System.Drawing.Bitmap bitmap)
{
IntPtr ip = bitmap.GetHbitmap();
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ip, IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);//释放对象
return bitmapSource;
}
#endregion