From 63ecb20f9e58b8c7b9bede1c9aec93c5a2ada04d Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 7 Feb 2014 10:23:17 +0100 Subject: [PATCH] Fix for losing EXIF and other information, eventually causing the image to be incorrectly rotated. --- GreenshotPlugin/Core/ClipboardHelper.cs | 12 +++++------- GreenshotPlugin/Core/ImageHelper.cs | 12 +++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/GreenshotPlugin/Core/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs index f89727fc5..015b2313e 100644 --- a/GreenshotPlugin/Core/ClipboardHelper.cs +++ b/GreenshotPlugin/Core/ClipboardHelper.cs @@ -330,9 +330,7 @@ EndSelection:<<<<<<<4 LOG.Info("Using default .NET Clipboard.GetImage()"); try { returnImage = Clipboard.GetImage(); - if (returnImage != null) { - return returnImage; - } else { + if (returnImage == null) { LOG.Info("Clipboard.GetImage() didn't return an image."); } } catch (Exception ex) { @@ -345,13 +343,13 @@ EndSelection:<<<<<<<4 } else { returnImage = GetImageFormat(currentFormat, dataObject); } - if (returnImage != null) { - ImageHelper.Orientate(returnImage); - return returnImage; - } } else { LOG.DebugFormat("Couldn't find format {0}.", currentFormat); } + if (returnImage != null) { + ImageHelper.Orientate(returnImage); + return returnImage; + } } } return null; diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 9ad528362..37c9089bc 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -1143,7 +1143,7 @@ namespace GreenshotPlugin.Core { newImage = new Bitmap(bitmapRect.Width, bitmapRect.Height, targetFormat); // 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 @@ -1162,6 +1162,16 @@ namespace GreenshotPlugin.Core { // Make sure both images have the same resolution newImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); } + // Clone property items (EXIF information etc) + if (sourceImage.PropertyItems != null) { + foreach (var propertyItem in sourceImage.PropertyItems) { + try { + newImage.SetPropertyItem(propertyItem); + } catch (Exception ex) { + LOG.Warn("Problem cloning a propertyItem.", ex); + } + } + } return newImage; }