---
title: "Swap Channels Memory Friendly"
canonical: https://www.graphicsmill.com/samples/ColorManagement/Channels/SwapChannelsMemoryFriendly_cs
product: "Graphics Mill"
source: "ColorManagement/Channels/SwapChannelsMemoryFriendly.cs"
---

# Swap Channels Memory Friendly

Demonstrates how to swap the Red and Green channels of an image using a memory-friendly pipeline approach.

## Instruction

Demonstrates how to swap the Red and Green channels of an image using a memory-friendly pipeline approach.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
```

## Code Snippet

```csharp
////                         /-- (R) ------- (R)--\
////                        /                      \
//// reader --->  splitter  ---- (G) --\ /-- (B)----  combiner  ---> writer
////                        \           X          /
////                         \-- (B) --/ \-- (G)--/
using (var reader = ImageReader.Create("Chicago.jpg"))
using (var splitter = new RgbChannelSplitter())
using (var combiner = new RgbChannelCombiner())
using (var writer = ImageWriter.Create("SwapChannelsMemoryFriendly.jpg"))
{
    reader.Receivers.Add(splitter);

    combiner.R = splitter.R;
    combiner.G = splitter.B;
    combiner.B = splitter.G;

    combiner.Receivers.Add(writer);

    Pipeline.Run(combiner);
}
```

## Explanation

The following code:

- Reads the image (`Chicago.jpg`) using `ImageReader`.
- Splits the image into separate RGB channels with `RgbChannelSplitter`.
- Swaps the Red and Green channels by assigning the `R` channel to the `B` and the `G` channel to the `R`.
- Combines the swapped channels back using `RgbChannelCombiner`.
- Saves the resulting image as `SwapChannelsMemoryFriendly.jpg`.

## Tags

- [Channels](<https://www.graphicsmill.com/samples/tags/channels_md>): Reading and combining image channels
- [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

- [SwapChannelsMemoryFriendly.jpg](<https://www.graphicsmill.com/samples/ColorManagement/compiled/Debug/SwapChannelsMemoryFriendly_jpg>) (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.PipelineElement.Receivers](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_PipelineElement_Receivers.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelCombiner](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelCombiner.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelCombiner.B](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelCombiner_B.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelCombiner.G](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelCombiner_G.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelCombiner.R](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelCombiner_R.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelSplitter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelSplitter.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelSplitter.B](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelSplitter_B.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelSplitter.G](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelSplitter_G.htm.md>)
- [Aurigma.GraphicsMill.RgbChannelSplitter.R](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_RgbChannelSplitter_R.htm.md>)
