Clearing PointF[] shape in an image to transparent pixels clears bounding box also #340
Replies: 2 comments
-
I've attempted to set the value of PixelAlphaCompositionMode in GraphicsOption to PixelAlphaCompositionMode.Clear, but the same issue persists |
Beta Was this translation helpful? Give feedback.
-
Yes, there's something weird going on here. If I translate the clear operation into the equivalent fill matching the internal behavior I can replicate the issue using Image<Rgba32> canvas = new Image<Rgba32>(1000, 1000, Color.HotPink);
PointF[] points = new PointF[] { new(512, 128), new(896, 512), new(512, 896), new(128, 512) };
GraphicsOptions options = new(){
AlphaCompositionMode = PixelAlphaCompositionMode.Src,
ColorBlendingMode = PixelColorBlendingMode.Normal,
BlendPercentage = 1F
};
canvas.Mutate(i => i.Fill(new DrawingOptions() {GraphicsOptions = options}, Color.Transparent, new Polygon(points)));
canvas.Save(@$"C:\Users\james\Downloads\340-clear.png"); However, while the bounds are cleared there is something deeper going on. If I change the color to It looks to me like the composition is doing the right thing but the polygon scanner is giving the brush the bounds to work on. @tocsoft would you concur with this analysis? |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm wanting to set use a PointF[] to set a part of an image to transparent.
When giving it a PointF[], it seems to Clear the pixel data correctly by setting the shape given to transparent, but it also seems to remove the colour data for the bounding box of the shape too.
Here's an example:
testInput.png:
testOutput1.png (FillPolygon() using the PointF[]):
testOutput2.png (Clear() using the PointF[]):
As you can see, it seems to also remove the colour information for all pixels in the bounding box of the shape.
testOutput2.png (Clear() using the PointF[]) (if switching the commented line to use a non-transparent colour):
This shows it setting the shape to the correct colour, but also removing the bounding box pixel data.
If there's another way I should be doing this instead, please let me know!
I've taken a look at your examples here, but they don't suit my needs: SixLabors/ImageSharp#1272
This is because I am using gradients, so cannot just replace a colour, and I am doing this many times so looping through all pixels many times slows it down a lot.
Clear() works perfectly for me, if it didn't seem to also remove the pixel data in the bounding box of the PointF[] polygon I'm giving it!
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions