---
title: "Add Alpha Channel (Memory Friendly)"
canonical: https://www.graphicsmill.com/samples/ColorManagement/Channels/AddAlphaChannelMemoryFriendly_cs
product: "Graphics Mill"
source: "ColorManagement/Channels/AddAlphaChannelMemoryFriendly.cs"
---

# Add Alpha Channel (Memory Friendly)

Generates an elliptical alpha channel and applies it to the source image using memory-friendly Pipeline API.

## Instruction

Demonstrates how to add an alpha channel to an image using a memory-friendly Pipeline API.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
// 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);
}
```

## Explanation

The following code:

- Loads the image from `Chicago.jpg` using `ImageReader`.
- Creates an empty alpha channel (grayscale image with transparent background) using `ImageGenerator`.
- Sets up a `Drawer` to draw a filled ellipse on the alpha channel.
- Uses `SetAlpha` to set the created alpha channel onto the image.
- Writes the resulting image (with the added alpha channel) to `AddAlphaChannelMemoryFriendly.png`.

## Tags

- [Channels](<https://www.graphicsmill.com/samples/tags/channels_md>): Reading and combining image channels
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Pipeline](<https://www.graphicsmill.com/samples/tags/pipeline_md>): Working with images via the Pipeline API

## Input

- [Chicago.jpg](<https://www.graphicsmill.com/samples/ColorManagement/compiled/Debug/Chicago_jpg>) (preview)

## Output

- [AddAlphaChannelMemoryFriendly.png](<https://www.graphicsmill.com/samples/ColorManagement/compiled/Debug/AddAlphaChannelMemoryFriendly_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.ImageReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_ImageReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Create(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ImageReader_Create_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_ImageWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageWriter.Create(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ImageWriter_Create_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Drawer](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Drawer.htm.md>)
- [Aurigma.GraphicsMill.Drawing.DrawEventArgs.Graphics](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_DrawEventArgs_Graphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillEllipse(Brush,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillEllipse_5_2d30ad96.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.GrayscaleColor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleColor.htm.md>)
- [Aurigma.GraphicsMill.ImageGenerator](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ImageGenerator.htm.md>)
- [Aurigma.GraphicsMill.Transforms.SetAlpha](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_SetAlpha.htm.md>)
- [Aurigma.GraphicsMill.Transforms.SetAlpha.AlphaSource](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_SetAlpha_AlphaSource.htm.md>)
