diff options
author | sr55 <[email protected]> | 2018-05-06 19:41:30 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-05-06 19:41:30 +0100 |
commit | 369c1bb661d0ef1dd3fcd43379294519cb479765 (patch) | |
tree | 42abaeb60bad86fec270713844df08571c2a7cca /win/CS/HandBrakeWPF | |
parent | c14555897d3f3742c4e035c2d6653336dd2b9165 (diff) |
WinGui: Remove references to System.Drawing from Alpha.ApplicationServices. The WPF project now has a conversion utility to take the raw byte[] to convert to bitmapimage.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Scan/LibScan.cs | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs | 30 |
2 files changed, 32 insertions, 1 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index 7558bc163..bb2703903 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -207,7 +207,8 @@ namespace HandBrakeWPF.Services.Scan PixelAspectY = job.PixelAspectY }; - bitmapImage = BitmapUtilities.ConvertToBitmapImage(this.instance.GetPreview(settings, preview, job.DeinterlaceFilter != DeinterlaceFilter.Off)); + var bitmapData = this.instance.GetPreview(settings, preview, job.DeinterlaceFilter != DeinterlaceFilter.Off); + bitmapImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(bitmapData)); } catch (AccessViolationException e) { diff --git a/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs index bc0f30061..0f5b64d53 100644 --- a/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs +++ b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs @@ -9,11 +9,16 @@ namespace HandBrakeWPF.Utilities { + using System; + using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; + using System.Runtime.InteropServices; using System.Windows.Media.Imaging; + using HandBrake.ApplicationServices.Interop.Model.Preview; + /// <summary> /// The bitmap utilities. /// </summary> @@ -52,5 +57,30 @@ namespace HandBrakeWPF.Utilities return wpfBitmap; } } + + public static Bitmap ConvertByteArrayToBitmap(RawPreviewData previewData) + { + var bitmap = new Bitmap(previewData.Width, previewData.Height); + + BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, previewData.Width, previewData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb); + + IntPtr ptr = bitmapData.Scan0; // Pointer to the first pixel. + for (int i = 0; i < previewData.Height; i++) + { + try + { + Marshal.Copy(previewData.RawBitmapData, i * previewData.StrideWidth, ptr, previewData.StrideWidth); + ptr = IntPtr.Add(ptr, previewData.Width * 4); + } + catch (Exception exc) + { + Debug.WriteLine(exc); // In theory, this will allow a partial image display if this happens. TODO add better logging of this. + } + } + + bitmap.UnlockBits(bitmapData); + + return bitmap; + } } } |