Hi, Support:
I want to know whether the aspose.imaging.dll support clipping a image to circle/oval/roundRetangle shape result, and save the clip image to png with backcolor transperance. If so ,how to work it out?
Thanks.
@ducaisoft, you can clip images using Graphics class and next example:
using (var image = (RasterImage)Aspose.Imaging.Image.Load(@"c:\Users\USER\Downloads\input(1).png"))
{
using (var image2 = new PngImage(image.Width, image.Height))
{
var g = new Graphics(image2);
g.Clear(Color.Transparent);
GraphicsPath path = new GraphicsPath();
var figure = new Figure();
//Circle or oval figure
EllipseShape ellipseshape = new EllipseShape(new RectangleF(200, 200, 100, 50));
figure.AddShape(ellipseshape);
path.AddFigure(figure);
//Round rectangle
GraphicsPath path2 = RoundedRect(100, 100, 100, 100, 8);
path.AddPath(path2);
g.Clip = new Region(path);
g.DrawImage(image, new Point(0, 0));
image2.Save(@"c:\Users\USER\Downloads\result.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
}
public static GraphicsPath RoundedRect(int x, int y, int width, int height, int radius)
{
Rectangle corner = new Rectangle(x, y, radius, radius);
GraphicsPath path = new GraphicsPath();
ArcShape shape = new ArcShape(corner, 180, 90);
var figure = new Figure();
figure.AddShape(shape);
corner.X = x + width - radius;
shape = new ArcShape(corner, 270, 90);
figure.AddShape(shape);
corner.Y = y + height - radius;
shape = new ArcShape(corner, 0, 90);
figure.AddShape(shape);
corner.X = x;
shape = new ArcShape(corner, 90, 90);
figure.AddShape(shape);
figure.IsClosed = true;
path.AddFigure(figure);
return path;
}
Thank you very much.
And else, how to apply opacity (0-255) parameter to the output image?
@ducaisoft you can make using How to overlay 4 images with mixed and transparence? - #2 by samer.el-khatib you need to change Alpha of your image like pixel.A = pixel.A*opacity.