Add Alpha Channel (Memory Friendly)
View as MarkdownGenerates an elliptical alpha channel and applies it to the source image using memory-friendly Pipeline API.
Code Snippet
// reader ---------------> setAlpha ---> writer
// alpha ---> drawer ---/
using (var reader = ImageReader.Create("Chicago.jpg"))
using (var alpha = new ImageGenerator(reader.Width, reader.Height, PixelFormat.Format8bppGrayscale, new GrayscaleColor(0)))
using (var drawer = new Drawer())
using (var setAlpha = new SetAlpha())
using (var writer = ImageWriter.Create("AddAlphaChannelMemoryFriendly.png"))
{
drawer.Draw += (sender, e) =>
{
e.Graphics.FillEllipse(
new SolidBrush(new GrayscaleColor(255)),
0,
0,
reader.Width,
reader.Height);
};
setAlpha.AlphaSource = alpha + drawer;
Pipeline.Run(reader + setAlpha + writer);
}
Input
Chicago.jpg
Output
AddAlphaChannelMemoryFriendly.png
Used APIs
- Aurigma.GraphicsMill.Codecs.ImageReader
- Aurigma.GraphicsMill.Codecs.ImageReader.Create(String)
- Aurigma.GraphicsMill.Codecs.ImageWriter
- Aurigma.GraphicsMill.Codecs.ImageWriter.Create(String)
- Aurigma.GraphicsMill.Drawing.Drawer
- Aurigma.GraphicsMill.Drawing.DrawEventArgs.Graphics
- Aurigma.GraphicsMill.Drawing.Graphics.FillEllipse(Brush,Single,Single,Single,Single)
- Aurigma.GraphicsMill.Drawing.SolidBrush
- Aurigma.GraphicsMill.GrayscaleColor
- Aurigma.GraphicsMill.ImageGenerator
- Aurigma.GraphicsMill.Transforms.SetAlpha
- Aurigma.GraphicsMill.Transforms.SetAlpha.AlphaSource