mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 11:10:23 +12:00
Refactor FillBackground
This commit is contained in:
parent
e13f893193
commit
ed64fb1050
|
@ -776,7 +776,6 @@ public static Bitmap FillBackground(Image img, Brush brush)
|
|||
{
|
||||
Bitmap result = img.CreateEmptyBitmap();
|
||||
|
||||
using (img)
|
||||
using (Graphics g = Graphics.FromImage(result))
|
||||
{
|
||||
g.FillRectangle(brush, 0, 0, result.Width, result.Height);
|
||||
|
@ -2478,16 +2477,9 @@ public static void SaveJPEG(Image img, Stream stream, int quality, bool fillBack
|
|||
{
|
||||
if (fillBackgroundWhite)
|
||||
{
|
||||
try
|
||||
using (Image newImage = FillBackground(img, Color.White))
|
||||
{
|
||||
img = (Image)img.Clone();
|
||||
img = FillBackground(img, Color.White);
|
||||
|
||||
SaveJPEGInternal(img, stream, quality);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (img != null) img.Dispose();
|
||||
SaveJPEGInternal(newImage, stream, quality);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -59,12 +59,15 @@ private void AddDefaultGradient()
|
|||
|
||||
public override Bitmap Apply(Bitmap bmp)
|
||||
{
|
||||
if (UseGradient && Gradient != null && Gradient.IsValid)
|
||||
using (bmp)
|
||||
{
|
||||
return ImageHelpers.FillBackground(bmp, Gradient);
|
||||
}
|
||||
if (UseGradient && Gradient != null && Gradient.IsValid)
|
||||
{
|
||||
return ImageHelpers.FillBackground(bmp, Gradient);
|
||||
}
|
||||
|
||||
return ImageHelpers.FillBackground(bmp, Color);
|
||||
return ImageHelpers.FillBackground(bmp, Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -299,23 +299,13 @@ public static string CreateThumbnail(Bitmap bmp, string folder, string filename,
|
|||
|
||||
if (!string.IsNullOrEmpty(thumbnailFilePath))
|
||||
{
|
||||
Bitmap thumbnail = null;
|
||||
|
||||
try
|
||||
using (Bitmap thumbnail = (Bitmap)bmp.Clone())
|
||||
using (Bitmap resizedImage = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbnail))
|
||||
using (Bitmap newImage = ImageHelpers.FillBackground(resizedImage, Color.White))
|
||||
{
|
||||
thumbnail = (Bitmap)bmp.Clone();
|
||||
thumbnail = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbnail);
|
||||
thumbnail = ImageHelpers.FillBackground(thumbnail, Color.White);
|
||||
ImageHelpers.SaveJPEG(thumbnail, thumbnailFilePath, 90);
|
||||
ImageHelpers.SaveJPEG(newImage, thumbnailFilePath, 90);
|
||||
return thumbnailFilePath;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (thumbnail != null)
|
||||
{
|
||||
thumbnail.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue