码迷,mamicode.com
首页 > 其他好文 > 详细

图像类型的互转

时间:2016-10-04 14:07:58      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

图像类型的互转 

 1 static class ImageConverter
 2 {
 3     public static ImageSource ToImageSource(this Bitmap bitmap)
 4     {
 5         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
 6     }
 7 
 8     public static BitmapSource ToBitmapSource(this Bitmap bitmap)
 9     {
10         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
11     }
12 
13     public static Icon ToIcon(this Bitmap bitmap)
14     {
15         return Icon.FromHandle(bitmap.GetHicon());
16     }
17 
18     public static Image ToImage(this Bitmap bitmap)
19     {
20         return Image.FromHbitmap(bitmap.GetHbitmap());
21     }
22 
23     public static ImageSource ToImageSource(this Icon icon)
24     {
25         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
26     }
27 }

 

图像类型的互转

标签:

原文地址:http://www.cnblogs.com/Bita/p/5584460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!