diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index 7435d057d..3e66b7938 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -224,19 +224,6 @@ public static Image ResizeImageLimit(Image img, int size) return ResizeImageLimit(img, size, size); } - public static Image CropImage(Image img, Rectangle rect) - { - if (img != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, img.Width, img.Height).Contains(rect)) - { - using (Bitmap bmp = new Bitmap(img)) - { - return bmp.Clone(rect, bmp.PixelFormat); - } - } - - return null; - } - public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect) { if (bmp != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(rect)) @@ -406,12 +393,12 @@ public static Bitmap QuickAutoCropTransparent(Bitmap bmp) return bmp; } - public static Image AddCanvas(Image img, Padding margin) + public static Bitmap AddCanvas(Image img, Padding margin) { return AddCanvas(img, margin, Color.Transparent); } - public static Image AddCanvas(Image img, Padding margin, Color canvasColor) + public static Bitmap AddCanvas(Image img, Padding margin, Color canvasColor) { if (margin.All == 0 || img.Width + margin.Horizontal < 1 || img.Height + margin.Vertical < 1) { @@ -930,7 +917,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size) public static Bitmap AddShadow(Image img, float opacity, int size, float darkness, Color color, Point offset) { - Image shadowImage = null; + Bitmap shadowImage = null; try { @@ -950,7 +937,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes if (size > 0) { - BoxBlur((Bitmap)shadowImage, size); + BoxBlur(shadowImage, size); } if (darkness > 1) @@ -958,7 +945,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes ColorMatrix alphaMatrix = new ColorMatrix(); alphaMatrix.Matrix33 = darkness; - Image shadowImage2 = alphaMatrix.Apply(shadowImage); + Bitmap shadowImage2 = (Bitmap)alphaMatrix.Apply(shadowImage); shadowImage.Dispose(); shadowImage = shadowImage2; } @@ -981,16 +968,15 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes } } - public static Bitmap Sharpen(Image img, double strength) + public static Bitmap Sharpen(Bitmap bmp, double strength) { - using (Bitmap bitmap = (Bitmap)img) + if (bmp != null) { - if (bitmap != null) + using (bmp) { - Bitmap sharpenImage = bitmap.Clone() as Bitmap; - - int width = img.Width; - int height = img.Height; + Bitmap sharpenImage = (Bitmap)bmp.Clone(); + int width = sharpenImage.Width; + int height = sharpenImage.Height; // Create sharpening filter. const int filterSize = 5; @@ -1009,75 +995,73 @@ public static Bitmap Sharpen(Image img, double strength) const int s = filterSize / 2; - Color[,] result = new Color[img.Width, img.Height]; + Color[,] result = new Color[sharpenImage.Width, sharpenImage.Height]; // Lock image bits for read/write. - if (sharpenImage != null) + BitmapData pbits = sharpenImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); + + // Declare an array to hold the bytes of the bitmap. + int bytes = pbits.Stride * height; + byte[] rgbValues = new byte[bytes]; + + // Copy the RGB values into the array. + Marshal.Copy(pbits.Scan0, rgbValues, 0, bytes); + + int rgb; + // Fill the color array with the new sharpened color values. + for (int x = s; x < width - s; x++) { - BitmapData pbits = sharpenImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); - - // Declare an array to hold the bytes of the bitmap. - int bytes = pbits.Stride * height; - byte[] rgbValues = new byte[bytes]; - - // Copy the RGB values into the array. - Marshal.Copy(pbits.Scan0, rgbValues, 0, bytes); - - int rgb; - // Fill the color array with the new sharpened color values. - for (int x = s; x < width - s; x++) + for (int y = s; y < height - s; y++) { - for (int y = s; y < height - s; y++) - { - double red = 0.0, green = 0.0, blue = 0.0; + double red = 0.0, green = 0.0, blue = 0.0; - for (int filterX = 0; filterX < filterSize; filterX++) + for (int filterX = 0; filterX < filterSize; filterX++) + { + for (int filterY = 0; filterY < filterSize; filterY++) { - for (int filterY = 0; filterY < filterSize; filterY++) - { - int imageX = (x - s + filterX + width) % width; - int imageY = (y - s + filterY + height) % height; + int imageX = (x - s + filterX + width) % width; + int imageY = (y - s + filterY + height) % height; - rgb = (imageY * pbits.Stride) + (3 * imageX); + rgb = (imageY * pbits.Stride) + (3 * imageX); - red += rgbValues[rgb + 2] * filter[filterX, filterY]; - green += rgbValues[rgb + 1] * filter[filterX, filterY]; - blue += rgbValues[rgb + 0] * filter[filterX, filterY]; - } - - rgb = (y * pbits.Stride) + (3 * x); - - int r = Math.Min(Math.Max((int)((factor * red) + (bias * rgbValues[rgb + 2])), 0), 255); - int g = Math.Min(Math.Max((int)((factor * green) + (bias * rgbValues[rgb + 1])), 0), 255); - int b = Math.Min(Math.Max((int)((factor * blue) + (bias * rgbValues[rgb + 0])), 0), 255); - - result[x, y] = Color.FromArgb(r, g, b); + red += rgbValues[rgb + 2] * filter[filterX, filterY]; + green += rgbValues[rgb + 1] * filter[filterX, filterY]; + blue += rgbValues[rgb + 0] * filter[filterX, filterY]; } - } - } - // Update the image with the sharpened pixels. - for (int x = s; x < width - s; x++) - { - for (int y = s; y < height - s; y++) - { rgb = (y * pbits.Stride) + (3 * x); - rgbValues[rgb + 2] = result[x, y].R; - rgbValues[rgb + 1] = result[x, y].G; - rgbValues[rgb + 0] = result[x, y].B; + int r = Math.Min(Math.Max((int)((factor * red) + (bias * rgbValues[rgb + 2])), 0), 255); + int g = Math.Min(Math.Max((int)((factor * green) + (bias * rgbValues[rgb + 1])), 0), 255); + int b = Math.Min(Math.Max((int)((factor * blue) + (bias * rgbValues[rgb + 0])), 0), 255); + + result[x, y] = Color.FromArgb(r, g, b); } } - - // Copy the RGB values back to the bitmap. - Marshal.Copy(rgbValues, 0, pbits.Scan0, bytes); - // Release image bits. - sharpenImage.UnlockBits(pbits); } + // Update the image with the sharpened pixels. + for (int x = s; x < width - s; x++) + { + for (int y = s; y < height - s; y++) + { + rgb = (y * pbits.Stride) + (3 * x); + + rgbValues[rgb + 2] = result[x, y].R; + rgbValues[rgb + 1] = result[x, y].G; + rgbValues[rgb + 0] = result[x, y].B; + } + } + + // Copy the RGB values back to the bitmap. + Marshal.Copy(rgbValues, 0, pbits.Scan0, bytes); + // Release image bits. + sharpenImage.UnlockBits(pbits); + return sharpenImage; } } + return null; } @@ -1634,7 +1618,7 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u { sfd.Filter = "PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (*.tif, *.tiff)|*.tif;*.tiff"; sfd.DefaultExt = "png"; - + string initialDirectory = null; if (useLastDirectory && !string.IsNullOrEmpty(HelpersOptions.LastSaveDirectory) && Directory.Exists(HelpersOptions.LastSaveDirectory)) diff --git a/ShareX.ImageEffectsLib/Manipulations/Crop.cs b/ShareX.ImageEffectsLib/Manipulations/Crop.cs index 0f0d608bb..7759589ec 100644 --- a/ShareX.ImageEffectsLib/Manipulations/Crop.cs +++ b/ShareX.ImageEffectsLib/Manipulations/Crop.cs @@ -59,7 +59,7 @@ public override Image Apply(Image img) { if (Margin.All == 0) return img; - return ImageHelpers.CropImage(img, new Rectangle(Margin.Left, Margin.Top, img.Width - Margin.Horizontal, img.Height - Margin.Vertical)); + return ImageHelpers.CropBitmap((Bitmap)img, new Rectangle(Margin.Left, Margin.Top, img.Width - Margin.Horizontal, img.Height - Margin.Vertical)); } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs index 49ddd2515..d27823f79 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs @@ -1285,7 +1285,7 @@ internal void UpdateRegionPath() } } - public Image GetResultImage() + public Bitmap GetResultImage() { if (IsEditorMode) { @@ -1304,9 +1304,9 @@ public Image GetResultImage() gp = regionFillPath; } - using (Image img = RegionCaptureTasks.ApplyRegionPathToImage(Canvas, gp, out Rectangle rect)) + using (Bitmap bmp = RegionCaptureTasks.ApplyRegionPathToImage(Canvas, gp, out Rectangle rect)) { - return ShapeManager.RenderOutputImage(img, rect.Location); + return ShapeManager.RenderOutputImage(bmp, rect.Location); } } else if (Result == RegionResult.Fullscreen) @@ -1322,9 +1322,9 @@ public Image GetResultImage() Screen screen = screens[MonitorIndex]; Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds); - using (Image img = ShapeManager.RenderOutputImage(Canvas)) + using (Bitmap bmp = ShapeManager.RenderOutputImage(Canvas)) { - return ImageHelpers.CropImage(img, screenRect); + return ImageHelpers.CropBitmap(bmp, screenRect); } } } @@ -1332,9 +1332,9 @@ public Image GetResultImage() { Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based(); - using (Image img = ShapeManager.RenderOutputImage(Canvas)) + using (Bitmap bmp = ShapeManager.RenderOutputImage(Canvas)) { - return ImageHelpers.CropImage(img, activeScreenRect); + return ImageHelpers.CropBitmap(bmp, activeScreenRect); } } diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureLightForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureLightForm.cs index 1961817b7..66fcf4213 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureLightForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureLightForm.cs @@ -162,7 +162,7 @@ private void RectangleLight_MouseUp(object sender, MouseEventArgs e) } } - public Image GetAreaImage() + public Bitmap GetAreaImage() { Rectangle rect = SelectionRectangle0Based; @@ -170,10 +170,10 @@ public Image GetAreaImage() { if (rect.X == 0 && rect.Y == 0 && rect.Width == backgroundImage.Width && rect.Height == backgroundImage.Height) { - return (Image)backgroundImage.Clone(); + return (Bitmap)backgroundImage.Clone(); } - return ImageHelpers.CropImage(backgroundImage, rect); + return ImageHelpers.CropBitmap(backgroundImage, rect); } return null; diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs index ec0f42b47..edf8e2fbb 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs @@ -45,7 +45,7 @@ public partial class ScrollingCaptureForm : Form private WindowInfo selectedWindow; private Rectangle selectedRectangle; - private List images = new List(); + private List images = new List(); private int currentScrollCount; private bool isBusy, isCapturing, firstCapture, detectingScrollMethod; private ScrollingCaptureScrollMethod currentScrollMethod; @@ -244,11 +244,11 @@ private void Clean() if (images != null) { - foreach (Image image in images) + foreach (Bitmap bmp in images) { - if (image != null) + if (bmp != null) { - image.Dispose(); + bmp.Dispose(); } } @@ -279,13 +279,13 @@ private void RemoveDuplicates() { for (int i = images.Count - 1; i > 0; i--) { - bool result = ImageHelpers.IsImagesEqual((Bitmap)images[i], (Bitmap)images[i - 1]); + bool result = ImageHelpers.IsImagesEqual(images[i], images[i - 1]); if (result) { - Image img = images[i]; - images.Remove(img); - img.Dispose(); + Bitmap bmp = images[i]; + images.Remove(bmp); + bmp.Dispose(); } } } @@ -315,11 +315,11 @@ private void captureTimer_Tick(object sender, EventArgs e) } Screenshot screenshot = new Screenshot() { CaptureCursor = false }; - Image image = screenshot.CaptureRectangle(selectedRectangle); + Bitmap bmp = screenshot.CaptureRectangle(selectedRectangle); - if (image != null) + if (bmp != null) { - images.Add(image); + images.Add(bmp); } if (Options.ScrollMethod == ScrollingCaptureScrollMethod.Automatic && detectingScrollMethod && images.Count > 1 && IsLastTwoImagesSame()) @@ -433,11 +433,11 @@ private bool IsLastTwoImagesSame() if (images.Count > 1) { - result = ImageHelpers.IsImagesEqual((Bitmap)images[images.Count - 1], (Bitmap)images[images.Count - 2]); + result = ImageHelpers.IsImagesEqual(images[images.Count - 1], images[images.Count - 2]); if (result) { - Image last = images[images.Count - 1]; + Bitmap last = images[images.Count - 1]; images.Remove(last); last.Dispose(); } @@ -571,15 +571,15 @@ private Image CombineImages() if (images.Count == 1) { - return (Image)images[0].Clone(); + return (Bitmap)images[0].Clone(); } - List output = new List(); + List output = new List(); for (int i = 0; i < images.Count - Options.IgnoreLast; i++) { - Image newImage; - Image image = images[i]; + Bitmap newImage; + Bitmap image = images[i]; if (Options.TrimLeftEdge > 0 || Options.TrimTopEdge > 0 || Options.TrimRightEdge > 0 || Options.TrimBottomEdge > 0 || Options.CombineAdjustmentVertical > 0 || Options.CombineAdjustmentLastVertical > 0) @@ -598,7 +598,7 @@ private Image CombineImages() rect.Height -= Options.CombineAdjustmentVertical; } - newImage = ImageHelpers.CropImage(image, rect); + newImage = ImageHelpers.CropBitmap(image, rect); if (newImage == null) { @@ -607,7 +607,7 @@ private Image CombineImages() } else { - newImage = (Image)image.Clone(); + newImage = (Bitmap)image.Clone(); } output.Add(newImage); @@ -615,7 +615,7 @@ private Image CombineImages() Image result = ImageHelpers.CombineImages(output); - foreach (Image image in output) + foreach (Bitmap image in output) { if (image != null) { @@ -664,13 +664,13 @@ private void chkAutoUpload_CheckedChanged(object sender, EventArgs e) Options.AutoUpload = chkAutoUpload.Checked; } - private Padding GuessEdges(Image img1, Image img2) + private Padding GuessEdges(Bitmap img1, Bitmap img2) { Padding result = new Padding(); Rectangle rect = new Rectangle(0, 0, img1.Width, img1.Height); - using (UnsafeBitmap bmp1 = new UnsafeBitmap((Bitmap)img1, true, ImageLockMode.ReadOnly)) - using (UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)img2, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap bmp1 = new UnsafeBitmap(img1, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap bmp2 = new UnsafeBitmap(img2, true, ImageLockMode.ReadOnly)) { bool valueFound = false; @@ -761,7 +761,7 @@ private void GuessCombineAdjustments() } } - private int CalculateVerticalOffset(Image img1, Image img2, int ignoreRightOffset = 50) + private int CalculateVerticalOffset(Bitmap img1, Bitmap img2, int ignoreRightOffset = 50) { int lastMatchCount = 0; int lastMatchOffset = 0; @@ -770,8 +770,8 @@ private int CalculateVerticalOffset(Image img1, Image img2, int ignoreRightOffse img1.Width - Options.TrimLeftEdge - Options.TrimRightEdge - (img1.Width > ignoreRightOffset ? ignoreRightOffset : 0), img1.Height - Options.TrimTopEdge - Options.TrimBottomEdge); - using (UnsafeBitmap bmp1 = new UnsafeBitmap((Bitmap)img1, true, ImageLockMode.ReadOnly)) - using (UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)img2, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap bmp1 = new UnsafeBitmap(img1, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap bmp2 = new UnsafeBitmap(img2, true, ImageLockMode.ReadOnly)) { for (int y = rect.Y; y < rect.Bottom; y++) { diff --git a/ShareX.ScreenCaptureLib/RegionCaptureTasks.cs b/ShareX.ScreenCaptureLib/RegionCaptureTasks.cs index 289c1991d..e97ecb786 100644 --- a/ShareX.ScreenCaptureLib/RegionCaptureTasks.cs +++ b/ShareX.ScreenCaptureLib/RegionCaptureTasks.cs @@ -32,7 +32,7 @@ namespace ShareX.ScreenCaptureLib { public static class RegionCaptureTasks { - public static Image GetRegionImage(RegionCaptureOptions options) + public static Bitmap GetRegionImage(RegionCaptureOptions options) { RegionCaptureOptions newOptions = GetRegionCaptureOptions(options); @@ -158,9 +158,9 @@ public static void ShowScreenRuler(RegionCaptureOptions options) } } - public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp, out Rectangle resultArea) + public static Bitmap ApplyRegionPathToImage(Bitmap bmp, GraphicsPath gp, out Rectangle resultArea) { - if (img != null && gp != null) + if (bmp != null && gp != null) { Rectangle regionArea = Rectangle.Round(gp.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); @@ -168,16 +168,16 @@ public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp, out Recta if (resultArea.IsValid()) { - using (Bitmap bmp = img.CreateEmptyBitmap()) - using (Graphics g = Graphics.FromImage(bmp)) - using (TextureBrush brush = new TextureBrush(img)) + using (Bitmap bmpResult = bmp.CreateEmptyBitmap()) + using (Graphics g = Graphics.FromImage(bmpResult)) + using (TextureBrush brush = new TextureBrush(bmp)) { g.PixelOffsetMode = PixelOffsetMode.Half; g.SmoothingMode = SmoothingMode.HighQuality; g.FillPath(brush, gp); - return ImageHelpers.CropBitmap(bmp, resultArea); + return ImageHelpers.CropBitmap(bmpResult, resultArea); } } } diff --git a/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs b/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs index 36e34a27a..112e676fd 100644 --- a/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs +++ b/ShareX.ScreenCaptureLib/Screenshot_Transparent.cs @@ -93,17 +93,17 @@ public Image CaptureWindowTransparent(IntPtr handle) Thread.Sleep(10); Application.DoEvents(); - whiteBackground = (Bitmap)CaptureRectangleNative(rect); + whiteBackground = CaptureRectangleNative(rect); form.BackColor = Color.Black; Application.DoEvents(); - blackBackground = (Bitmap)CaptureRectangleNative(rect); + blackBackground = CaptureRectangleNative(rect); form.BackColor = Color.White; Application.DoEvents(); - whiteBackground2 = (Bitmap)CaptureRectangleNative(rect); + whiteBackground2 = CaptureRectangleNative(rect); form.Close(); } diff --git a/ShareX.ScreenCaptureLib/Shapes/Effect/BaseEffectShape.cs b/ShareX.ScreenCaptureLib/Shapes/Effect/BaseEffectShape.cs index 5c49c508a..d5ee5bde4 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Effect/BaseEffectShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Effect/BaseEffectShape.cs @@ -37,7 +37,7 @@ public abstract class BaseEffectShape : BaseShape public abstract string OverlayText { get; } private bool drawCache, isEffectCaching, isCachePending, isDisposePending; - private Image cachedEffect; + private Bitmap cachedEffect; public abstract void ApplyEffect(Bitmap bmp); @@ -155,7 +155,7 @@ private void CacheEffect() Task.Run(() => { - ApplyEffect((Bitmap)cachedEffect); + ApplyEffect(cachedEffect); isEffectCaching = false; diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index db10eeef6..d554aecea 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -1261,14 +1261,14 @@ public WindowInfo FindSelectedWindowInfo(Point position) return null; } - public Image RenderOutputImage(Image img) + public Bitmap RenderOutputImage(Bitmap bmp) { - return RenderOutputImage(img, Point.Empty); + return RenderOutputImage(bmp, Point.Empty); } - public Image RenderOutputImage(Image img, Point offset) + public Bitmap RenderOutputImage(Bitmap bmp, Point offset) { - Bitmap bmp = new Bitmap(img); + Bitmap bmpOutput = (Bitmap)bmp.Clone(); if (DrawingShapes.Length > 0 || EffectShapes.Length > 0) { @@ -1277,13 +1277,13 @@ public Image RenderOutputImage(Image img, Point offset) MoveAll(-offset.X, -offset.Y); - using (Graphics g = Graphics.FromImage(bmp)) + using (Graphics g = Graphics.FromImage(bmpOutput)) { foreach (BaseEffectShape shape in EffectShapes) { if (shape != null) { - shape.OnDrawFinal(g, bmp); + shape.OnDrawFinal(g, bmpOutput); } } @@ -1302,7 +1302,7 @@ public Image RenderOutputImage(Image img, Point offset) IsRenderingOutput = false; } - return bmp; + return bmpOutput; } private void SelectShape(BaseShape shape) @@ -1787,7 +1787,7 @@ private void InsertImageFile() private void InsertImageFromScreen() { - Image img; + Bitmap bmp; try { @@ -1796,7 +1796,7 @@ private void InsertImageFromScreen() menuForm.Hide(); Thread.Sleep(250); - img = RegionCaptureTasks.GetRegionImage(Options); + bmp = RegionCaptureTasks.GetRegionImage(Options); } finally { @@ -1805,7 +1805,7 @@ private void InsertImageFromScreen() Form.Resume(); } - InsertImage(img); + InsertImage(bmp); } private void InsertImage(Image img) @@ -1905,7 +1905,7 @@ private void ChangeCanvasSize() if (canvasSizeForm.ShowDialog(Form) == DialogResult.OK) { Padding canvas = canvasSizeForm.Canvas; - Bitmap bmp = (Bitmap)ImageHelpers.AddCanvas(Form.Canvas, canvas, Options.EditorCanvasColor); + Bitmap bmp = ImageHelpers.AddCanvas(Form.Canvas, canvas, Options.EditorCanvasColor); if (bmp != null) { @@ -1933,7 +1933,7 @@ public void AutoResizeCanvas() private void ChangeCanvasSize(Padding margin, Color canvasColor) { - Bitmap bmp = (Bitmap)ImageHelpers.AddCanvas(Form.Canvas, margin, canvasColor); + Bitmap bmp = ImageHelpers.AddCanvas(Form.Canvas, margin, canvasColor); if (bmp != null) { diff --git a/ShareX/CaptureHelpers/CaptureLastRegion.cs b/ShareX/CaptureHelpers/CaptureLastRegion.cs index 249b6f881..42bc4f0cd 100644 --- a/ShareX/CaptureHelpers/CaptureLastRegion.cs +++ b/ShareX/CaptureHelpers/CaptureLastRegion.cs @@ -39,10 +39,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings) case RegionCaptureType.Default: if (RegionCaptureForm.LastRegionFillPath != null) { - using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) + using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) { - Image img = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath, out _); - return new ImageInfo(img); + Bitmap bmp = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath, out _); + return new ImageInfo(bmp); } } else @@ -52,10 +52,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings) case RegionCaptureType.Light: if (!RegionCaptureLightForm.LastSelectionRectangle0Based.IsEmpty) { - using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) + using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) { - Image img = ImageHelpers.CropImage(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based); - return new ImageInfo(img); + Bitmap bmp = ImageHelpers.CropBitmap(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based); + return new ImageInfo(bmp); } } else @@ -65,10 +65,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings) case RegionCaptureType.Transparent: if (!RegionCaptureTransparentForm.LastSelectionRectangle0Based.IsEmpty) { - using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) + using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen()) { - Image img = ImageHelpers.CropImage(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based); - return new ImageInfo(img); + Bitmap bmp = ImageHelpers.CropBitmap(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based); + return new ImageInfo(bmp); } } else diff --git a/ShareX/CaptureHelpers/CaptureRegion.cs b/ShareX/CaptureHelpers/CaptureRegion.cs index a05aea5fa..697bc770a 100644 --- a/ShareX/CaptureHelpers/CaptureRegion.cs +++ b/ShareX/CaptureHelpers/CaptureRegion.cs @@ -118,22 +118,22 @@ protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings) protected ImageInfo ExecuteRegionCaptureLight(TaskSettings taskSettings) { - Image img = null; + Bitmap bmp = null; using (RegionCaptureLightForm rectangleLight = new RegionCaptureLightForm(TaskHelpers.GetScreenshot(taskSettings))) { if (rectangleLight.ShowDialog() == DialogResult.OK) { - img = rectangleLight.GetAreaImage(); + bmp = rectangleLight.GetAreaImage(); - if (img != null) + if (bmp != null) { lastRegionCaptureType = RegionCaptureType.Light; } } } - return new ImageInfo(img); + return new ImageInfo(bmp); } protected ImageInfo ExecuteRegionCaptureTransparent(TaskSettings taskSettings) diff --git a/ShareX/Forms/QRCodeForm.cs b/ShareX/Forms/QRCodeForm.cs index 4f836ff4b..a57a3897e 100644 --- a/ShareX/Forms/QRCodeForm.cs +++ b/ShareX/Forms/QRCodeForm.cs @@ -218,11 +218,11 @@ private void btnDecodeFromScreen_Click(object sender, EventArgs e) TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings(); - using (Image img = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions)) + using (Bitmap bmp = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions)) { - if (img != null) + if (bmp != null) { - DecodeImage((Bitmap)img); + DecodeImage(bmp); } } } diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 903f65af9..f3fa32fe4 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -1011,7 +1011,7 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas return null; case RegionResult.Region: // Enter case RegionResult.AnnotateRunAfterCaptureTasks: - return (Bitmap)form.GetResultImage(); + return form.GetResultImage(); case RegionResult.Fullscreen: // Space or right click case RegionResult.AnnotateContinueTask: return (Bitmap)form.Canvas.Clone(); @@ -1123,9 +1123,9 @@ public static async Task OCRImage(TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); - using (Image img = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions)) + using (Bitmap bmp = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions)) { - await OCRImage(img, taskSettings); + await OCRImage(bmp, taskSettings); } } }