diff --git a/ColorRegionMaskCreator/ImageMasks.cs b/ColorRegionMaskCreator/ImageMasks.cs index 70016ab..cbc083c 100644 --- a/ColorRegionMaskCreator/ImageMasks.cs +++ b/ColorRegionMaskCreator/ImageMasks.cs @@ -80,7 +80,7 @@ private static void CreateFiles(string baseImageFilePath, string colorMaskFile, using (Bitmap bmpColorMask = File.Exists(colorMaskFile) ? new Bitmap(colorMaskFile) : null) { BitmapData bmpDataJpg = bmpBackgroundJpg.LockBits( - new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), + new Rectangle(0, 0, bmpBackgroundJpg.Width, bmpBackgroundJpg.Height), ImageLockMode.ReadWrite, bmpBackgroundJpg.PixelFormat); BitmapData bmpDataBackground = bmpBackground.LockBits(new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), ImageLockMode.ReadWrite, bmpBackground.PixelFormat); @@ -236,25 +236,8 @@ byte ApplyLightnessCorrection(byte val, double factor) var imageWidth = (int)(bmpBackground.Width * resizeFactor); var imageHeight = (int)(bmpBackground.Height * resizeFactor); - SaveResizedBitmap(bmpBackground, filePathBaseImage); - SaveResizedBitmap(bmpColorMask, filePathMaskImage); - - void SaveResizedBitmap(Bitmap bmp, string filePath) - { - if (bmp == null) return; - - using (var bmpResized = new Bitmap(imageWidth, imageHeight, bmp.PixelFormat)) - using (var g = Graphics.FromImage(bmpResized)) - { - g.CompositingMode = CompositingMode.SourceCopy; - g.CompositingQuality = CompositingQuality.HighQuality; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.SmoothingMode = SmoothingMode.HighQuality; - g.PixelOffsetMode = PixelOffsetMode.HighQuality; - g.DrawImage(bmp, 0, 0, imageWidth, imageWidth); - bmpResized.Save(filePath, ImageFormat.Png); - } - } + SaveResizedBitmap(bmpBackground, filePathBaseImage, imageWidth, imageHeight); + SaveResizedBitmap(bmpColorMask, filePathMaskImage, imageWidth, imageHeight); if (createRegionImages && bmpColorMask != null) { @@ -279,13 +262,31 @@ void SaveResizedBitmap(Bitmap bmp, string filePath) { if (CreateColorRegionImages(colors, enabledColorRegions, filePathMaskImage, regionImage)) SaveResizedBitmap(regionImage, - Path.Combine(OutputRegionsFolderPath, Path.GetFileNameWithoutExtension(baseImageFilePath) + "_PaintRegion_" + i + ".png")); + Path.Combine(OutputRegionsFolderPath, Path.GetFileNameWithoutExtension(baseImageFilePath) + "_PaintRegion_" + i + ".png"), + imageWidth, imageHeight); } } } } } + private static void SaveResizedBitmap(Bitmap bmp, string filePath, int imageWidth, int imageHeight) + { + if (bmp == null) return; + + using (var bmpResized = new Bitmap(imageWidth, imageHeight, bmp.PixelFormat)) + using (var g = Graphics.FromImage(bmpResized)) + { + g.CompositingMode = CompositingMode.SourceCopy; + g.CompositingQuality = CompositingQuality.HighQuality; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.SmoothingMode = SmoothingMode.HighQuality; + g.PixelOffsetMode = PixelOffsetMode.HighQuality; + g.DrawImage(bmp, 0, 0, imageWidth, imageHeight); + bmpResized.Save(filePath, ImageFormat.Png); + } + } + /// /// Creates a transformation for lightness values to create a gaussian histogram. /// diff --git a/ColorRegionMaskCreator/Properties/AssemblyInfo.cs b/ColorRegionMaskCreator/Properties/AssemblyInfo.cs index dbbd559..01d379a 100644 --- a/ColorRegionMaskCreator/Properties/AssemblyInfo.cs +++ b/ColorRegionMaskCreator/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] diff --git a/ColorRegionMaskCreator/config.ini b/ColorRegionMaskCreator/config.ini index 5d7901b..a9c9f2a 100644 --- a/ColorRegionMaskCreator/config.ini +++ b/ColorRegionMaskCreator/config.ini @@ -1,6 +1,6 @@ ; max size of the output images. Smaller images are not enlarged -maxWidth = 600 -maxHeight = 800 +maxWidth = 800 +maxHeight = 600 ; Color of the region highlighting colorR = 240