From fe9e5e6c35f7d96dae5867b6aa0f9b4ed3d108e0 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 17 Feb 2012 16:56:46 +0000 Subject: [PATCH] Fixed resolution regression bug, again I forgot to copy the horizontal & vertical resolution of the original image... git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1664 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/ImageHelper.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 009554704..4ec6b4218 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -220,6 +220,9 @@ namespace GreenshotPlugin.Core { } } } + if (fileBitmap != null) { + LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", filename, fileBitmap.Width, fileBitmap.Height, fileBitmap.PixelFormat, fileBitmap.HorizontalResolution, fileBitmap.VerticalResolution); + } return fileBitmap; } @@ -648,6 +651,7 @@ namespace GreenshotPlugin.Core { // copy back to image Bitmap newImage = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, sourceBitmap.PixelFormat); + newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); var bits2 = newImage.LockBits(rct, ImageLockMode.ReadWrite, newImage.PixelFormat); Marshal.Copy(dest, 0, bits2.Scan0, dest.Length); newImage.UnlockBits(bits); @@ -795,6 +799,8 @@ namespace GreenshotPlugin.Core { public static Bitmap CreateGrayscale(Bitmap sourceBitmap) { //create a blank bitmap the same size as original Bitmap newBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height); + // Make sure both images have the same resolution + newBitmap.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); //get a graphics object from the new image using (Graphics graphics = Graphics.FromImage(newBitmap)) { @@ -898,6 +904,9 @@ namespace GreenshotPlugin.Core { if (isAreaEqual || fromTransparentToNon || !isBitmap) { // Rule 1: if the areas are equal, always copy ourselves newImage = new Bitmap(bitmapRect.Width, bitmapRect.Height, targetFormat); + // Make sure both images have the same resolution + newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); + using (Graphics graphics = Graphics.FromImage(newImage)) { if (fromTransparentToNon) { // Rule 2: Make sure the background color is white @@ -913,9 +922,9 @@ namespace GreenshotPlugin.Core { } else { // Let GDI+ decide how to convert, need to test what is quicker... newImage = (sourceBitmap as Bitmap).Clone(sourceRect, targetFormat); + // Make sure both images have the same resolution + newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); } - // Make sure both images have the same resolution - newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); return newImage; } }