// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Defines the BitmapUtilities type. // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Utilities { using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Media.Imaging; /// /// The bitmap utilities. /// public class BitmapUtilities { /// /// Convert a Bitmap to a BitmapImagetype. /// /// /// The bitmap. /// /// /// The . /// public static BitmapImage ConvertToBitmapImage(Bitmap bitmap) { // Create a Bitmap Image for display. using (var memoryStream = new MemoryStream()) { try { bitmap.Save(memoryStream, ImageFormat.Bmp); } finally { bitmap.Dispose(); } var wpfBitmap = new BitmapImage(); wpfBitmap.BeginInit(); wpfBitmap.CacheOption = BitmapCacheOption.OnLoad; wpfBitmap.StreamSource = memoryStream; wpfBitmap.EndInit(); wpfBitmap.Freeze(); return wpfBitmap; } } } }