C#,WPF中 BitMap转BitmapImage

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         }

猜你喜欢

转载自www.cnblogs.com/MichaelJson/p/12894497.html
今日推荐