diff options
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Scan/LibScan.cs | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs | 56 |
3 files changed, 59 insertions, 1 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 207083bd6..2717b5da1 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -241,6 +241,7 @@ <Compile Include="Services\UserSettingService.cs" />
<Compile Include="Startup\StartupOptions.cs" />
<Compile Include="Utilities\AppcastReader.cs" />
+ <Compile Include="Utilities\BitmapUtilities.cs" />
<Compile Include="Utilities\DelayedActionProcessor.cs" />
<Compile Include="Utilities\DPIAwareness.cs" />
<Compile Include="Utilities\DriveUtilities.cs" />
diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index 2d875ca0c..ea81a9c03 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -31,6 +31,7 @@ namespace HandBrakeWPF.Services.Scan using HandBrakeWPF.Services.Scan.EventArgs; using HandBrakeWPF.Services.Scan.Interfaces; using HandBrakeWPF.Services.Scan.Model; + using HandBrakeWPF.Utilities; using Chapter = HandBrakeWPF.Services.Scan.Model.Chapter; using ScanProgressEventArgs = HandBrake.ApplicationServices.Interop.EventArgs.ScanProgressEventArgs; @@ -201,7 +202,7 @@ namespace HandBrakeWPF.Services.Scan PixelAspectY = job.PixelAspectY }; - bitmapImage = this.instance.GetPreview(settings, preview); + bitmapImage = BitmapUtilities.ConvertToBitmapImage(this.instance.GetPreview(settings, preview)); } catch (AccessViolationException e) { diff --git a/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs new file mode 100644 index 000000000..bc0f30061 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs @@ -0,0 +1,56 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="BitmapUtilities.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the BitmapUtilities type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System.Drawing; + using System.Drawing.Imaging; + using System.IO; + using System.Windows.Media.Imaging; + + /// <summary> + /// The bitmap utilities. + /// </summary> + public class BitmapUtilities + { + /// <summary> + /// Convert a Bitmap to a BitmapImagetype. + /// </summary> + /// <param name="bitmap"> + /// The bitmap. + /// </param> + /// <returns> + /// The <see cref="BitmapImage"/>. + /// </returns> + 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; + } + } + } +} |