From c1bcb15d98df126e4c0fcfff638beaa2370f33ce Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 22 Mar 2020 01:07:38 +0300 Subject: [PATCH] Use bitmap in manipulation image effects --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 116 +++++++++--------- ShareX.HelpersLib/ShareXResources.cs | 2 +- ShareX.ImageEffectsLib/ImageEffectsForm.cs | 2 +- .../Manipulations/AutoCrop.cs | 4 +- .../Manipulations/Canvas.cs | 12 +- ShareX.ImageEffectsLib/Manipulations/Crop.cs | 6 +- ShareX.ImageEffectsLib/Manipulations/Flip.cs | 6 +- .../Manipulations/Resize.cs | 23 ++-- .../Manipulations/Rotate.cs | 12 +- .../Manipulations/RoundedCorners.cs | 4 +- ShareX.ImageEffectsLib/Manipulations/Scale.cs | 9 +- ShareX.ImageEffectsLib/Manipulations/Skew.cs | 6 +- ShareX.ImageEffectsLib/WatermarkConfig.cs | 6 +- ShareX.MediaLib/VideoThumbnailer.cs | 14 +-- .../Shapes/Drawing/StickerDrawingShape.cs | 8 +- ShareX/Forms/NotificationForm.cs | 2 +- ShareX/TaskHelpers.cs | 18 +-- ShareX/TaskManager.cs | 2 +- ShareX/WorkerTask.cs | 2 +- 19 files changed, 136 insertions(+), 118 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index 0be1ead41..037a45368 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -41,18 +41,18 @@ public static class ImageHelpers { private const InterpolationMode DefaultInterpolationMode = InterpolationMode.HighQualityBicubic; - public static Image ResizeImage(Image img, int width, int height, InterpolationMode interpolationMode = DefaultInterpolationMode) + public static Bitmap ResizeImage(Bitmap bmp, int width, int height, InterpolationMode interpolationMode = DefaultInterpolationMode) { - if (width < 1 || height < 1 || (img.Width == width && img.Height == height)) + if (width < 1 || height < 1 || (bmp.Width == width && bmp.Height == height)) { - return img; + return bmp; } - Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); - bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution); + Bitmap bmpResult = new Bitmap(width, height, PixelFormat.Format32bppArgb); + bmpResult.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution); - using (img) - using (Graphics g = Graphics.FromImage(bmp)) + using (bmp) + using (Graphics g = Graphics.FromImage(bmpResult)) { g.InterpolationMode = interpolationMode; g.SmoothingMode = SmoothingMode.HighQuality; @@ -63,28 +63,28 @@ public static Image ResizeImage(Image img, int width, int height, InterpolationM using (ImageAttributes ia = new ImageAttributes()) { ia.SetWrapMode(WrapMode.TileFlipXY); - g.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia); + g.DrawImage(bmp, new Rectangle(0, 0, width, height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia); } } - return bmp; + return bmpResult; } - public static Image ResizeImage(Image img, Size size, InterpolationMode interpolationMode = DefaultInterpolationMode) + public static Bitmap ResizeImage(Bitmap bmp, Size size, InterpolationMode interpolationMode = DefaultInterpolationMode) { - return ResizeImage(img, size.Width, size.Height, interpolationMode); + return ResizeImage(bmp, size.Width, size.Height, interpolationMode); } - public static Image ResizeImageByPercentage(Image img, float percentageWidth, float percentageHeight, InterpolationMode interpolationMode = DefaultInterpolationMode) + public static Bitmap ResizeImageByPercentage(Bitmap bmp, float percentageWidth, float percentageHeight, InterpolationMode interpolationMode = DefaultInterpolationMode) { - int width = (int)Math.Round(percentageWidth / 100 * img.Width); - int height = (int)Math.Round(percentageHeight / 100 * img.Height); - return ResizeImage(img, width, height, interpolationMode); + int width = (int)Math.Round(percentageWidth / 100 * bmp.Width); + int height = (int)Math.Round(percentageHeight / 100 * bmp.Height); + return ResizeImage(bmp, width, height, interpolationMode); } - public static Image ResizeImageByPercentage(Image img, float percentage, InterpolationMode interpolationMode = DefaultInterpolationMode) + public static Bitmap ResizeImageByPercentage(Bitmap bmp, float percentage, InterpolationMode interpolationMode = DefaultInterpolationMode) { - return ResizeImageByPercentage(img, percentage, percentage, interpolationMode); + return ResizeImageByPercentage(bmp, percentage, percentage, interpolationMode); } public static Image ResizeImage(Image img, Size size, bool allowEnlarge, bool centerImage = true) @@ -192,36 +192,36 @@ public static Image CreateThumbnail(Image img, int width, int height) } /// If image size is bigger than specified size then resize it and keep aspect ratio else return image. - public static Image ResizeImageLimit(Image img, int width, int height) + public static Bitmap ResizeImageLimit(Bitmap bmp, int width, int height) { - if (img.Width <= width && img.Height <= height) + if (bmp.Width <= width && bmp.Height <= height) { - return img; + return bmp; } - double ratioX = (double)width / img.Width; - double ratioY = (double)height / img.Height; + double ratioX = (double)width / bmp.Width; + double ratioY = (double)height / bmp.Height; if (ratioX < ratioY) { - height = (int)Math.Round(img.Height * ratioX); + height = (int)Math.Round(bmp.Height * ratioX); } else if (ratioX > ratioY) { - width = (int)Math.Round(img.Width * ratioY); + width = (int)Math.Round(bmp.Width * ratioY); } - return ResizeImage(img, width, height); + return ResizeImage(bmp, width, height); } - public static Image ResizeImageLimit(Image img, Size size) + public static Bitmap ResizeImageLimit(Bitmap bmp, Size size) { - return ResizeImageLimit(img, size.Width, size.Height); + return ResizeImageLimit(bmp, size.Width, size.Height); } - public static Image ResizeImageLimit(Image img, int size) + public static Bitmap ResizeImageLimit(Bitmap bmp, int size) { - return ResizeImageLimit(img, size, size); + return ResizeImageLimit(bmp, size, size); } public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect) @@ -445,28 +445,28 @@ public static Bitmap AddCanvas(Image img, Padding margin, Color canvasColor) return bmp; } - public static Image RoundedCorners(Image img, int cornerRadius) + public static Bitmap RoundedCorners(Bitmap bmp, int cornerRadius) { - Bitmap bmp = img.CreateEmptyBitmap(); + Bitmap bmpResult = bmp.CreateEmptyBitmap(); - using (Graphics g = Graphics.FromImage(bmp)) - using (img) + using (bmp) + using (Graphics g = Graphics.FromImage(bmpResult)) { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.Half; using (GraphicsPath gp = new GraphicsPath()) { - gp.AddRoundedRectangleProper(new RectangleF(0, 0, img.Width, img.Height), cornerRadius, 0); + gp.AddRoundedRectangleProper(new RectangleF(0, 0, bmp.Width, bmp.Height), cornerRadius, 0); - using (TextureBrush brush = new TextureBrush(img)) + using (TextureBrush brush = new TextureBrush(bmp)) { g.FillPath(brush, gp); } } } - return bmp; + return bmpResult; } public static Bitmap Outline(Bitmap bmp, int borderSize, Color borderColor) @@ -527,8 +527,8 @@ public static Bitmap AddSkew(Image img, int x, int y) { Bitmap result = img.CreateEmptyBitmap(Math.Abs(x), Math.Abs(y)); - using (Graphics g = Graphics.FromImage(result)) using (img) + using (Graphics g = Graphics.FromImage(result)) { g.SetHighQuality(); int startX = -Math.Min(0, x); @@ -699,8 +699,8 @@ public static Bitmap FillBackground(Image img, Brush brush) { Bitmap result = img.CreateEmptyBitmap(); - using (Graphics g = Graphics.FromImage(result)) using (img) + using (Graphics g = Graphics.FromImage(result)) { g.FillRectangle(brush, 0, 0, result.Width, result.Height); g.DrawImage(img, 0, 0, result.Width, result.Height); @@ -847,20 +847,22 @@ public static void CopyMetadata(Image fromImage, Image toImage) /// Note that this method always returns a new Bitmap object, even if rotation is zero - in /// which case the returned object is a clone of the input object. /// - /// input Image object, is not modified + /// input Image object, is not modified /// angle of rotation, in degrees /// see comments above /// see comments above, not used if upsizeOk = true /// new Bitmap object, may be larger than input image - public static Bitmap RotateImage(Image img, float angleDegrees, bool upsize, bool clip) + public static Bitmap RotateImage(Bitmap bmp, float angleDegrees, bool upsize, bool clip) { // Test for zero rotation and return a clone of the input image if (angleDegrees == 0f) - return (Bitmap)img.Clone(); + { + return (Bitmap)bmp.Clone(); + } // Set up old and new image dimensions, assuming upsizing not wanted and clipping OK - int oldWidth = img.Width; - int oldHeight = img.Height; + int oldWidth = bmp.Width; + int oldHeight = bmp.Height; int newWidth = oldWidth; int newHeight = oldHeight; float scaleFactor = 1f; @@ -885,10 +887,10 @@ public static Bitmap RotateImage(Image img, float angleDegrees, bool upsize, boo } // Create the new bitmap object. - Bitmap newBitmap = img.CreateEmptyBitmap(); + Bitmap bmpResult = bmp.CreateEmptyBitmap(); // Create the Graphics object that does the work - using (Graphics g = Graphics.FromImage(newBitmap)) + using (Graphics g = Graphics.FromImage(bmpResult)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; @@ -898,16 +900,18 @@ public static Bitmap RotateImage(Image img, float angleDegrees, bool upsize, boo g.TranslateTransform(newWidth / 2f, newHeight / 2f); if (scaleFactor != 1f) + { g.ScaleTransform(scaleFactor, scaleFactor); + } g.RotateTransform(angleDegrees); g.TranslateTransform(-oldWidth / 2f, -oldHeight / 2f); // Draw the result - g.DrawImage(img, 0, 0, img.Width, img.Height); + g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height); } - return newBitmap; + return bmpResult; } public static Bitmap AddShadow(Bitmap bmp, float opacity, int size) @@ -1681,7 +1685,7 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u return null; } - public static Image LoadImage(string filePath) + public static Bitmap LoadImage(string filePath) { try { @@ -1692,14 +1696,14 @@ public static Image LoadImage(string filePath) if (!string.IsNullOrEmpty(filePath) && Helpers.IsImageFile(filePath) && File.Exists(filePath)) { // http://stackoverflow.com/questions/788335/why-does-image-fromfile-keep-a-file-handle-open-sometimes - Image img = Image.FromStream(new MemoryStream(File.ReadAllBytes(filePath))); + Bitmap bmp = (Bitmap)Image.FromStream(new MemoryStream(File.ReadAllBytes(filePath))); if (HelpersOptions.RotateImageByExifOrientationData) { - RotateImageByExifOrientationData(img); + RotateImageByExifOrientationData(bmp); } - return img; + return bmp; } } } @@ -1969,23 +1973,23 @@ public static void DrawColorPickerIcon(Graphics g, Color color, Rectangle rect, return bmp; } - public static RotateFlipType RotateImageByExifOrientationData(Image img, bool removeExifOrientationData = true) + public static RotateFlipType RotateImageByExifOrientationData(Bitmap bmp, bool removeExifOrientationData = true) { int orientationId = 0x0112; RotateFlipType rotateType = RotateFlipType.RotateNoneFlipNone; - if (img.PropertyIdList.Contains(orientationId)) + if (bmp.PropertyIdList.Contains(orientationId)) { - PropertyItem propertyItem = img.GetPropertyItem(orientationId); + PropertyItem propertyItem = bmp.GetPropertyItem(orientationId); rotateType = GetRotateFlipTypeByExifOrientationData(propertyItem.Value[0]); if (rotateType != RotateFlipType.RotateNoneFlipNone) { - img.RotateFlip(rotateType); + bmp.RotateFlip(rotateType); if (removeExifOrientationData) { - img.RemovePropertyItem(orientationId); + bmp.RemovePropertyItem(orientationId); } } } diff --git a/ShareX.HelpersLib/ShareXResources.cs b/ShareX.HelpersLib/ShareXResources.cs index df2427882..e28d1bea2 100644 --- a/ShareX.HelpersLib/ShareXResources.cs +++ b/ShareX.HelpersLib/ShareXResources.cs @@ -73,7 +73,7 @@ public static bool ExperimentalCustomTheme public static Icon Icon => UseWhiteIcon ? Resources.ShareX_Icon_White : Resources.ShareX_Icon; - public static Image Logo => Resources.ShareX_Logo; + public static Bitmap Logo => Resources.ShareX_Logo; public static ShareXTheme Theme { get; set; } = new ShareXTheme(); diff --git a/ShareX.ImageEffectsLib/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/ImageEffectsForm.cs index e5b05a5e1..48242a2a3 100644 --- a/ShareX.ImageEffectsLib/ImageEffectsForm.cs +++ b/ShareX.ImageEffectsLib/ImageEffectsForm.cs @@ -301,7 +301,7 @@ private void GeneratePreviewImage(int padding) if (PreviewImage.Width > 260 && PreviewImage.Height > 260) { - using (Image logo = ShareXResources.Logo) + using (Bitmap logo = ShareXResources.Logo) { g.DrawImage(logo, (PreviewImage.Width / 2) - (logo.Width / 2), (PreviewImage.Height / 2) - (logo.Height / 2)); } diff --git a/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs b/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs index 2241e9ae4..8041162db 100644 --- a/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs +++ b/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs @@ -41,9 +41,9 @@ public AutoCrop() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.AutoCropImage((Bitmap)img, false, Sides); + return ImageHelpers.AutoCropImage(bmp, false, Sides); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Canvas.cs b/ShareX.ImageEffectsLib/Manipulations/Canvas.cs index ca9442e3f..168fa9726 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Canvas.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Canvas.cs @@ -44,17 +44,17 @@ public Canvas() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - Image result = ImageHelpers.AddCanvas(img, Margin, Color); + Bitmap bmpResult = ImageHelpers.AddCanvas(bmp, Margin, Color); - if (result == null) + if (bmpResult == null) { - return img; + return bmp; } - img.Dispose(); - return result; + bmp.Dispose(); + return bmpResult; } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Crop.cs b/ShareX.ImageEffectsLib/Manipulations/Crop.cs index 7759589ec..0759997a7 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Crop.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Crop.cs @@ -55,11 +55,11 @@ public Crop() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - if (Margin.All == 0) return img; + if (Margin.All == 0) return bmp; - return ImageHelpers.CropBitmap((Bitmap)img, new Rectangle(Margin.Left, Margin.Top, img.Width - Margin.Horizontal, img.Height - Margin.Vertical)); + return ImageHelpers.CropBitmap(bmp, new Rectangle(Margin.Left, Margin.Top, bmp.Width - Margin.Horizontal, bmp.Height - Margin.Vertical)); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Flip.cs b/ShareX.ImageEffectsLib/Manipulations/Flip.cs index 1e3f94298..08944f526 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Flip.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Flip.cs @@ -42,7 +42,7 @@ public Flip() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { RotateFlipType flipType = RotateFlipType.RotateNoneFlipNone; @@ -61,10 +61,10 @@ public override Image Apply(Image img) if (flipType != RotateFlipType.RotateNoneFlipNone) { - img.RotateFlip(flipType); + bmp.RotateFlip(flipType); } - return img; + return bmp; } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Resize.cs b/ShareX.ImageEffectsLib/Manipulations/Resize.cs index 67363c9bd..617642320 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Resize.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Resize.cs @@ -51,20 +51,23 @@ public Resize(int width, int height) Height = height; } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - if (Width <= 0 && Height <= 0) return img; - - int width = Width <= 0 ? (int)((float)Height / img.Height * img.Width) : Width; - int height = Height <= 0 ? (int)((float)Width / img.Width * img.Height) : Height; - - if ((Mode == ResizeMode.ResizeIfBigger && img.Width <= width && img.Height <= height) || - (Mode == ResizeMode.ResizeIfSmaller && img.Width >= width && img.Height >= height)) + if (Width <= 0 && Height <= 0) { - return img; + return bmp; } - return ImageHelpers.ResizeImage(img, width, height); + int width = Width <= 0 ? (int)((float)Height / bmp.Height * bmp.Width) : Width; + int height = Height <= 0 ? (int)((float)Width / bmp.Width * bmp.Height) : Height; + + if ((Mode == ResizeMode.ResizeIfBigger && bmp.Width <= width && bmp.Height <= height) || + (Mode == ResizeMode.ResizeIfSmaller && bmp.Width >= width && bmp.Height >= height)) + { + return bmp; + } + + return ImageHelpers.ResizeImage(bmp, width, height); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Rotate.cs b/ShareX.ImageEffectsLib/Manipulations/Rotate.cs index 7b48d2b49..78ef88a8b 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Rotate.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Rotate.cs @@ -45,9 +45,17 @@ public Rotate() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.RotateImage(img, Angle, Upsize, Clip); + if (Angle == 0) + { + return bmp; + } + + using (bmp) + { + return ImageHelpers.RotateImage(bmp, Angle, Upsize, Clip); + } } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/RoundedCorners.cs b/ShareX.ImageEffectsLib/Manipulations/RoundedCorners.cs index 3276b5876..759e86459 100644 --- a/ShareX.ImageEffectsLib/Manipulations/RoundedCorners.cs +++ b/ShareX.ImageEffectsLib/Manipulations/RoundedCorners.cs @@ -52,9 +52,9 @@ public RoundedCorners() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.RoundedCorners(img, CornerRadius); + return ImageHelpers.RoundedCorners(bmp, CornerRadius); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Scale.cs b/ShareX.ImageEffectsLib/Manipulations/Scale.cs index 5c84ba4e8..f15a6d410 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Scale.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Scale.cs @@ -42,14 +42,17 @@ public Scale() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - if (WidthPercentage <= 0 && HeightPercentage <= 0) return img; + if (WidthPercentage <= 0 && HeightPercentage <= 0) + { + return bmp; + } float widthPercentage = WidthPercentage <= 0 ? HeightPercentage : WidthPercentage; float heightPercentage = HeightPercentage <= 0 ? WidthPercentage : HeightPercentage; - return ImageHelpers.ResizeImageByPercentage(img, widthPercentage, heightPercentage); + return ImageHelpers.ResizeImageByPercentage(bmp, widthPercentage, heightPercentage); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Manipulations/Skew.cs b/ShareX.ImageEffectsLib/Manipulations/Skew.cs index 9ab7aff1d..d1c5573e6 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Skew.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Skew.cs @@ -42,14 +42,14 @@ public Skew() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { if (Horizontally == 0 && Vertically == 0) { - return img; + return bmp; } - return ImageHelpers.AddSkew(img, Horizontally, Vertically); + return ImageHelpers.AddSkew(bmp, Horizontally, Vertically); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/WatermarkConfig.cs b/ShareX.ImageEffectsLib/WatermarkConfig.cs index 66d9286bd..a00daf5c2 100644 --- a/ShareX.ImageEffectsLib/WatermarkConfig.cs +++ b/ShareX.ImageEffectsLib/WatermarkConfig.cs @@ -35,7 +35,7 @@ public class WatermarkConfig public DrawText Text = new DrawText { DrawTextShadow = false }; public DrawImage Image = new DrawImage(); - public Image Apply(Image img) + public Bitmap Apply(Bitmap bmp) { Text.Placement = Image.Placement = Placement; Text.Offset = Image.Offset = new Point(Offset, Offset); @@ -44,9 +44,9 @@ public Image Apply(Image img) { default: case WatermarkType.Text: - return Text.Apply(img); + return Text.Apply(bmp); case WatermarkType.Image: - return Image.Apply(img); + return Image.Apply(bmp); } } } diff --git a/ShareX.MediaLib/VideoThumbnailer.cs b/ShareX.MediaLib/VideoThumbnailer.cs index 7e57c04fe..591d04c85 100644 --- a/ShareX.MediaLib/VideoThumbnailer.cs +++ b/ShareX.MediaLib/VideoThumbnailer.cs @@ -192,7 +192,7 @@ private int GetRandomTimeSlice(int start) private Image CombineScreenshots(List thumbnails) { - List images = new List(); + List images = new List(); Image finalImage = null; try @@ -212,15 +212,15 @@ private Image CombineScreenshots(List thumbnails) foreach (VideoThumbnailInfo thumbnail in thumbnails) { - Image img = ImageHelpers.LoadImage(thumbnail.Filepath); + Bitmap bmp = ImageHelpers.LoadImage(thumbnail.Filepath); - if (Options.MaxThumbnailWidth > 0 && img.Width > Options.MaxThumbnailWidth) + if (Options.MaxThumbnailWidth > 0 && bmp.Width > Options.MaxThumbnailWidth) { - int maxThumbnailHeight = (int)((float)Options.MaxThumbnailWidth / img.Width * img.Height); - img = ImageHelpers.ResizeImage(img, Options.MaxThumbnailWidth, maxThumbnailHeight); + int maxThumbnailHeight = (int)((float)Options.MaxThumbnailWidth / bmp.Width * bmp.Height); + bmp = ImageHelpers.ResizeImage(bmp, Options.MaxThumbnailWidth, maxThumbnailHeight); } - images.Add(img); + images.Add(bmp); } int columnCount = Options.ColumnCount; @@ -317,7 +317,7 @@ private Image CombineScreenshots(List thumbnails) } finally { - foreach (Image image in images) + foreach (Bitmap image in images) { if (image != null) { diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/StickerDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/StickerDrawingShape.cs index cf6d5199a..8235cc527 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/StickerDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/StickerDrawingShape.cs @@ -105,15 +105,15 @@ private bool LoadSticker(string filePath, int stickerSize) { if (!string.IsNullOrEmpty(filePath)) { - Image img = ImageHelpers.LoadImage(filePath); + Bitmap bmp = ImageHelpers.LoadImage(filePath); - if (img != null) + if (bmp != null) { AnnotationOptions.LastStickerPath = filePath; - img = ImageHelpers.ResizeImageLimit(img, stickerSize); + bmp = ImageHelpers.ResizeImageLimit(bmp, stickerSize); - SetImage(img, true); + SetImage(bmp, true); return true; } diff --git a/ShareX/Forms/NotificationForm.cs b/ShareX/Forms/NotificationForm.cs index bf116bae7..ff85b521b 100644 --- a/ShareX/Forms/NotificationForm.cs +++ b/ShareX/Forms/NotificationForm.cs @@ -347,7 +347,7 @@ private void InitializeComponent() public class NotificationFormConfig : IDisposable { - public Image Image { get; set; } + public Bitmap Image { get; set; } public string Text { get; set; } public string FilePath { get; set; } public string URL { get; set; } diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index f3fa32fe4..8660d53d8 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -256,31 +256,31 @@ public static ImageData PrepareImage(Image img, TaskSettings taskSettings) return imageData; } - public static string CreateThumbnail(Image img, string folder, string filename, TaskSettings taskSettings) + public static string CreateThumbnail(Bitmap bmp, string folder, string filename, TaskSettings taskSettings) { if ((taskSettings.ImageSettings.ThumbnailWidth > 0 || taskSettings.ImageSettings.ThumbnailHeight > 0) && (!taskSettings.ImageSettings.ThumbnailCheckSize || - (img.Width > taskSettings.ImageSettings.ThumbnailWidth && img.Height > taskSettings.ImageSettings.ThumbnailHeight))) + (bmp.Width > taskSettings.ImageSettings.ThumbnailWidth && bmp.Height > taskSettings.ImageSettings.ThumbnailHeight))) { string thumbnailFileName = Path.GetFileNameWithoutExtension(filename) + taskSettings.ImageSettings.ThumbnailName + ".jpg"; string thumbnailFilePath = HandleExistsFile(folder, thumbnailFileName, taskSettings); if (!string.IsNullOrEmpty(thumbnailFilePath)) { - Image thumbImage = null; + Bitmap thumbnail = null; try { - thumbImage = (Image)img.Clone(); - thumbImage = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbImage); - thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White); - thumbImage.SaveJPG(thumbnailFilePath, 90); + thumbnail = (Bitmap)bmp.Clone(); + thumbnail = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbnail); + thumbnail = ImageHelpers.FillBackground(thumbnail, Color.White); + thumbnail.SaveJPG(thumbnailFilePath, 90); return thumbnailFilePath; } finally { - if (thumbImage != null) + if (thumbnail != null) { - thumbImage.Dispose(); + thumbnail.Dispose(); } } } diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index b13156392..f2b8c7f3e 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -390,7 +390,7 @@ private static void Task_TaskCompleted(WorkerTask task) RightClickAction = info.TaskSettings.AdvancedSettings.ToastWindowRightClickAction, MiddleClickAction = info.TaskSettings.AdvancedSettings.ToastWindowMiddleClickAction, FilePath = info.FilePath, - Image = task.Image, + Image = (Bitmap)task.Image, Text = "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed + "\r\n" + result, URL = result }; diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index 4afd1a9b4..2d71f2eff 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -683,7 +683,7 @@ private bool DoAfterCaptureJobs() thumbnailFolder = Info.TaskSettings.CaptureFolder; } - Info.ThumbnailFilePath = TaskHelpers.CreateThumbnail(Image, thumbnailFolder, thumbnailFilename, Info.TaskSettings); + Info.ThumbnailFilePath = TaskHelpers.CreateThumbnail((Bitmap)Image, thumbnailFolder, thumbnailFilename, Info.TaskSettings); if (!string.IsNullOrEmpty(Info.ThumbnailFilePath)) {