Convert Clipping Path To Mask
View as MarkdownConverts clipping path to alpha channel mask.
Code Snippet
using (var reader = new JpegReader("Apple.jpg"))
using (var bitmap = reader.Frames[0].GetBitmap())
using (var maskBitmap = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format8bppGrayscale, new GrayscaleColor(0)))
using (var graphics = maskBitmap.GetGraphics())
{
var graphicsPath = reader.ClippingPaths[0].CreateGraphicsPath(reader.Width, reader.Height);
graphics.FillPath(new SolidBrush(new GrayscaleColor(255)), Path.Create(graphicsPath));
bitmap.Channels.SetAlpha(maskBitmap);
bitmap.Save("ConvertClippingPathToMask.png");
}
Input
Apple.jpg
Output
ConvertClippingPathToMask.png
Used APIs
- Aurigma.GraphicsMill.Bitmap.Channels
- Aurigma.GraphicsMill.Bitmap.GetGraphics
- Aurigma.GraphicsMill.ChannelsProvider.SetAlpha(Bitmap)
- Aurigma.GraphicsMill.Codecs.ClippingPath.Path.CreateGraphicsPath(Int32,Int32)
- Aurigma.GraphicsMill.Codecs.Frame.GetBitmap
- Aurigma.GraphicsMill.Codecs.ImageReader.ClippingPaths
- Aurigma.GraphicsMill.Codecs.ImageReader.Frames
- Aurigma.GraphicsMill.Codecs.JpegReader
- Aurigma.GraphicsMill.Drawing.Graphics.FillPath(Brush,Path)
- Aurigma.GraphicsMill.Drawing.Path
- Aurigma.GraphicsMill.Drawing.Path.Create(GraphicsPath)
- Aurigma.GraphicsMill.Drawing.SolidBrush
- Aurigma.GraphicsMill.GrayscaleColor