From 769725ffcdc1c7950aed604aec6807b20bbe796e Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 29 Jan 2017 17:19:16 +0000 Subject: WinGui: Remove System.Windows.Forms, PresentationCore, PresentationFramework and WindowsBase from the Services library. This makes the library more portable. --- .../HandBrake.ApplicationServices.csproj | 4 -- .../Interop/HandBrakeInstance.cs | 27 ++--------- .../Interop/Interfaces/IHandBrakeInstance.cs | 4 +- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + win/CS/HandBrakeWPF/Services/Scan/LibScan.cs | 3 +- win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs | 56 ++++++++++++++++++++++ 6 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs (limited to 'win/CS') diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 14ba10545..0fd5b5260 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -56,8 +56,6 @@ False ..\libraries\json\Newtonsoft.Json.dll - - @@ -67,7 +65,6 @@ - 3.5 @@ -77,7 +74,6 @@ - diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index c39ad1534..f803887d1 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -19,7 +19,6 @@ namespace HandBrake.ApplicationServices.Interop using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Timers; - using System.Windows.Media.Imaging; using HandBrake.ApplicationServices.Interop.EventArgs; using HandBrake.ApplicationServices.Interop.Factories; @@ -269,7 +268,7 @@ namespace HandBrake.ApplicationServices.Interop /// An image with the requested preview. /// [HandleProcessCorruptedStateExceptions] - public BitmapImage GetPreview(PreviewSettings settings, int previewNumber) + public Bitmap GetPreview(PreviewSettings settings, int previewNumber) { SourceTitle title = this.Titles.TitleList.FirstOrDefault(t => t.Index == settings.TitleNumber); @@ -338,29 +337,9 @@ namespace HandBrake.ApplicationServices.Interop IntPtr nativeJobPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteIntPtr(nativeJobPtrPtr, resultingImageStuct); HBFunctions.hb_image_close(nativeJobPtrPtr); - Marshal.FreeHGlobal(nativeJobPtrPtr); + Marshal.FreeHGlobal(nativeJobPtrPtr); - // 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; - } + return bitmap; } /// diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs index 3e756d228..910621d81 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.Interfaces { using System; - using System.Windows.Media.Imaging; + using System.Drawing; using HandBrake.ApplicationServices.Interop.EventArgs; using HandBrake.ApplicationServices.Interop.Json.Encode; @@ -100,7 +100,7 @@ namespace HandBrake.ApplicationServices.Interop.Interfaces /// /// An image with the requested preview. /// - BitmapImage GetPreview(PreviewSettings job, int previewNumber); + Bitmap GetPreview(PreviewSettings job, int previewNumber); /// /// Pauses the current encode. 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 @@ + 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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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; + } + } + } +} -- cgit v1.2.3