对多边形应用高斯模糊或像素化

问题描述 投票:1回答:1

i能够在矩形区域上应用高斯模糊或像素化。

image.Mutate(x => x.GaussianBlur(5, new CoreRectangle(o.BoundingBox.X - 10, o.BoundingBox.Y - 10, o.BoundingBox.Width + 20, o.BoundingBox.Height + 20)));

是否可以使用n点多边形代替?有什么想法吗?

谢谢!约尔格

polygon blur effect imagesharp
1个回答
1
投票
这应该对您有用,它将克隆原始图像,对克隆应用效果,然后使用图像衬套将突变图像的正确部分完全填充到形状中。

using (Image image = Image.Load("fb.jpg")) { var outerRadii = Math.Min(image.Width, image.Height) / 2; var star = new Star(new PointF(image.Width / 2, image.Height / 2), 5, outerRadii / 2, outerRadii); // we want to clone our source image so we can apply // various effects to it without mutating the original. using (var clone = image.Clone(p => { p.GaussianBlur(15); // apply the effect here you and inside the shape })) { // crop the cloned down to just the size of the shape (this is due to the way ImageBrush works) clone.Mutate(x => x.Crop((Rectangle)star.Bounds)); // use an image brush to apply the section of cloned image as the source for filling the shape var brush = new ImageBrush(clone); // now fill the shape with the image brush containing the portion of // cloned image with the effects applied image.Mutate(c => c.Fill(brush, star)); } image.Save("output/fb.png"); }

这是最终结果的示例:

Resultant of blurred star

这是其他示例,可在ImageSharp样本存储库https://github.com/SixLabors/Samples中获得>

© www.soinside.com 2019 - 2024. All rights reserved.