fixed #596: Fix "Save thumbnail image to file" issue

This commit is contained in:
Jaex 2017-02-04 04:06:19 +03:00
parent a8ae843867
commit 3a4a8798c2
2 changed files with 17 additions and 11 deletions

View file

@ -45,6 +45,12 @@ public Resize()
this.ApplyDefaultPropertyValues(); this.ApplyDefaultPropertyValues();
} }
public Resize(int width, int height)
{
Width = width;
Height = height;
}
public override Image Apply(Image img) public override Image Apply(Image img)
{ {
if (Width <= 0 && Height <= 0) return img; if (Width <= 0 && Height <= 0) return img;

View file

@ -267,19 +267,11 @@ public static string CreateThumbnail(Image img, string folder, string filename,
try try
{ {
thumbImage = (Image)img.Clone(); thumbImage = (Image)img.Clone();
thumbImage = new Resize thumbImage = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbImage);
{
Width = taskSettings.ImageSettings.ThumbnailWidth,
Height = taskSettings.ImageSettings.ThumbnailHeight
}.Apply(thumbImage);
thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White); thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White);
thumbImage.SaveJPG(thumbnailFilePath, 90); thumbImage.SaveJPG(thumbnailFilePath, 90);
return thumbnailFilePath; return thumbnailFilePath;
} }
catch (Exception e)
{
DebugHelper.WriteException(e);
}
finally finally
{ {
if (thumbImage != null) if (thumbImage != null)
@ -308,8 +300,16 @@ public static MemoryStream SaveImageAsStream(Image img, EImageFormat imageFormat
img.Save(stream, ImageFormat.Png); img.Save(stream, ImageFormat.Png);
break; break;
case EImageFormat.JPEG: case EImageFormat.JPEG:
img = ImageHelpers.FillBackground(img, Color.White); try
img.SaveJPG(stream, jpegQuality); {
img = (Image)img.Clone();
img = ImageHelpers.FillBackground(img, Color.White);
img.SaveJPG(stream, jpegQuality);
}
finally
{
if (img != null) img.Dispose();
}
break; break;
case EImageFormat.GIF: case EImageFormat.GIF:
img.SaveGIF(stream, gifQuality); img.SaveGIF(stream, gifQuality);