Add Alpha Channel

Bitmap Channels Drawing

Generates an elliptical alpha channel and applies it to the source image.

Сode Snippet

using (var bitmap = new Bitmap("Chicago.jpg"))
using (var alpha = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format8bppGrayscale, new GrayscaleColor(0)))
using (var graphics = alpha.GetAdvancedGraphics())
{
    graphics.FillEllipse(
        new SolidBrush(new GrayscaleColor(255)),
        0,
        0,
        bitmap.Width,
        bitmap.Height);

    bitmap.Channels.SetAlpha(alpha);

    bitmap.Save("AddAlphaChannel.png");
}

Input

Chicago.jpg

Output

AddAlphaChannel.png

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog