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();
}
public Resize(int width, int height)
{
Width = width;
Height = height;
}
public override Image Apply(Image 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
{
thumbImage = (Image)img.Clone();
thumbImage = new Resize
{
Width = taskSettings.ImageSettings.ThumbnailWidth,
Height = taskSettings.ImageSettings.ThumbnailHeight
}.Apply(thumbImage);
thumbImage = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbImage);
thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White);
thumbImage.SaveJPG(thumbnailFilePath, 90);
return thumbnailFilePath;
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
finally
{
if (thumbImage != null)
@ -308,8 +300,16 @@ public static MemoryStream SaveImageAsStream(Image img, EImageFormat imageFormat
img.Save(stream, ImageFormat.Png);
break;
case EImageFormat.JPEG:
img = ImageHelpers.FillBackground(img, Color.White);
img.SaveJPG(stream, jpegQuality);
try
{
img = (Image)img.Clone();
img = ImageHelpers.FillBackground(img, Color.White);
img.SaveJPG(stream, jpegQuality);
}
finally
{
if (img != null) img.Dispose();
}
break;
case EImageFormat.GIF:
img.SaveGIF(stream, gifQuality);