C#,WPF中 BitMap转BitmapImage

时间:2020-05-15 14:03:57   收藏:0   阅读:414

 

 

WPF中System.Drawing.Bitmap类型转System.Windows.Media.Imaging.BitmapImage类型

 1         public static BitmapImage BitmapToBitmapImage(this System.Drawing.Bitmap bitmap)
 2         {
 3             var bitmapImage = new BitmapImage();
 4             using (MemoryStream ms = new MemoryStream())
 5             {
 6                 //bitmap.Save(ms, bitmap.RawFormat);
 7                 bitmap.Save(ms, ImageFormat.Png);
 8                 bitmapImage.BeginInit();
 9                 bitmapImage.StreamSource = ms;
10                 bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
11                 bitmapImage.EndInit();
12                 bitmapImage.Freeze();
13             }
14             return bitmapImage;
15         }

 

原文:https://www.cnblogs.com/MichaelJson/p/12894497.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!