Advertisement
andrew4582

WPF Bitmap To Image Source

Apr 5th, 2013
2,933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1.         BitmapImage BitmapToImageSource(System.Drawing.Bitmap bitmap, System.Drawing.Imaging.ImageFormat imgFormat)
  2.         {
  3.             using (MemoryStream memory = new MemoryStream())
  4.             {
  5.                 bitmap.Save(memory, imgFormat);
  6.                 memory.Position = 0;
  7.                 BitmapImage bitmapImage = new BitmapImage();
  8.                 bitmapImage.BeginInit();
  9.                 bitmapImage.StreamSource = memory;
  10.                 bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
  11.                 bitmapImage.EndInit();
  12.  
  13.                 return bitmapImage;
  14.             }
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement