首页 > 其他 > 详细

图像类型的互转

时间:2016-10-04 14:07:43      阅读:200      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!