From 98181e03e36549b72af162213bb813d83b3a7b3f Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Sat, 2 Jan 2021 21:53:47 +0100 Subject: [PATCH] THis fixes an exception when Greenshot is used via wine. --- GreenshotPlugin/Core/ImageHelper.cs | 57 +++++++++++++++++------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 8c31eaf4c..e5e5a1b60 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -1351,22 +1351,22 @@ namespace GreenshotPlugin.Core { // Make sure both images have the same resolution newImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); - using Graphics graphics = Graphics.FromImage(newImage); - if (fromTransparentToNon) - { - // Rule 2: Make sure the background color is white - graphics.Clear(Color.White); - } - // decide fastest copy method - if (isAreaEqual) - { - graphics.DrawImageUnscaled(sourceImage, 0, 0); - } - else - { - graphics.DrawImage(sourceImage, 0, 0, sourceRect, GraphicsUnit.Pixel); - } - } + using Graphics graphics = Graphics.FromImage(newImage); + if (fromTransparentToNon) + { + // Rule 2: Make sure the background color is white + graphics.Clear(Color.White); + } + // decide fastest copy method + if (isAreaEqual) + { + graphics.DrawImageUnscaled(sourceImage, 0, 0); + } + else + { + graphics.DrawImage(sourceImage, 0, 0, sourceRect, GraphicsUnit.Pixel); + } + } else { // Let GDI+ decide how to convert, need to test what is quicker... @@ -1374,18 +1374,27 @@ namespace GreenshotPlugin.Core { // Make sure both images have the same resolution newImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); } - // Clone property items (EXIF information etc) - foreach (var propertyItem in sourceImage.PropertyItems) + + // In WINE someone getting the PropertyItems doesn't work + try { - try + // Clone property items (EXIF information etc) + foreach (var propertyItem in sourceImage.PropertyItems) { - newImage.SetPropertyItem(propertyItem); - } - catch (Exception ex) - { - Log.Warn("Problem cloning a propertyItem.", ex); + try + { + newImage.SetPropertyItem(propertyItem); + } + catch (Exception innerEx) + { + Log.Warn("Problem cloning a propertyItem.", innerEx); + } } } + catch (Exception ex) + { + Log.Warn("Problem cloning a propertyItem.", ex); + } return newImage; }