From 7e3acc112d5bc43d3a8cf5febf64f16505910270 Mon Sep 17 00:00:00 2001 From: Wayfarer <petergeinitz@freenet.de> Date: Tue, 31 Dec 2024 10:58:11 +0100 Subject: [PATCH] add some mor stuff --- Imaging/FiltersAreas.cs | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/Imaging/FiltersAreas.cs b/Imaging/FiltersAreas.cs index 9903c7a..7326f1c 100644 --- a/Imaging/FiltersAreas.cs +++ b/Imaging/FiltersAreas.cs @@ -68,5 +68,66 @@ internal static Bitmap GenerateFilter(Bitmap image, return ImageStream.CombineBitmap(image, filterBitmap, 0, 0); } + /// <summary> + /// Fills the area with color. + /// </summary> + /// <param name="image">The image.</param> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> + /// <param name="shape">The shape.</param> + /// <param name="shapeParams">The shape parameters.</param> + /// <param name="startPoint">The optional starting point (top-left corner) of the rectangle. Defaults to (0, 0).</param> + /// <returns> + /// Generates a filter for a certain area + /// </returns> + /// <exception cref="System.ArgumentOutOfRangeException">filter - null + /// or + /// shape - null</exception> + internal static Bitmap FillAreaWithColor( + Bitmap image, + int width, + int height, + Color color, + MaskShape shape, + object shapeParams = null, + Point? startPoint = null) + { + // Validate input + if (image == null) throw new ArgumentNullException(nameof(image)); + + // Default start point + var actualStartPoint = startPoint ?? new Point(0, 0); + + using Graphics g = Graphics.FromImage(image); + using Brush brush = new SolidBrush(color); + + // Apply mask based on the specified shape + switch (shape) + { + case MaskShape.Rectangle: + g.FillRectangle(brush, new Rectangle(actualStartPoint, new Size(width, height))); + break; + + case MaskShape.Circle: + g.FillEllipse(brush, new Rectangle(actualStartPoint, new Size(width, height))); + break; + + case MaskShape.Polygon: + if (shapeParams is Point[] points) + { + g.FillPolygon(brush, points); + } + else + { + throw new ArgumentException("Invalid shape parameters for polygon mask.", nameof(shapeParams)); + } + break; + + default: + throw new ArgumentOutOfRangeException(nameof(shape), shape, "Unsupported shape type"); + } + + return image; + } } } \ No newline at end of file