---
title: "Reading and Writing Channels"
canonical: https://www.graphicsmill.com/docs/gm/reading-and-writing-channels.htm
product: "Graphics Mill"
---

# Reading and Writing Channels
 
In the digital imaging channel is a grayscale image of the size of the original image and containing a specific primary color from each original pixel. The number of image channels depends on how many primary colors are in the image. Also the channels can include the alpha channel, which itself does not contain color information but specifies opacity for each pixel. For example, an RGB image contains 3 channels (red, green, and blue), an aRGB image contains 4 channels (red, green, blue, and alpha), and so on. Channels of extended images are 16 bpp grayscale format, channels of regular images are 8 bpp grayscale. This topic examines working with color channels in Graphics Mill. Here you will learn how to:
 
- extract a channel from an image
- replace a channel with a bitmap
- split an image into channels
- create an image by merging several channels

**Note** 
Working with channels, as with using other Graphics Mill features, you can choose the API tier that suits you: the [Bitmap](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Bitmap.htm.md) class or pipelines. If you are not familiar with pipelines, read the [Understanding Image Processing Approaches in Graphics Mill](https://www.graphicsmill.com/docs/gm/understanding-image-processing-approaches-in-graphics-mill.htm.md) topic.
 
## Reading Channels
  
### Getting Channel
 
Using the [Bitmap.Channels](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Channels.htm.md) property you can get access to a single channel, either by its index or by the channel alias. (Note: channel order is described in the [Accessing Pixel Data](https://www.graphicsmill.com/docs/gm/accessing-pixel-data.htm.md) topic.) Since each channel is a bitmap itself, you can handle it as you would any other grayscale bitmap: draw on it, save it to a file, and so on. Channel alias can be specified through the [Channel](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Channel.htm.md) enumeration.
 
The following code gets the cyan and alpha channels from a CMYK with alpha image and saves them as grayscale TIFF images:
 
```csharp
using (var bitmap = new Bitmap(@"Images\cmyk.tif"))
{
    var cyanBitmap = bitmap.Channels[Channel.Cyan];
    cyanBitmap.Save(@"Images\Output\Cmyk_test_Channel_C.tif");

    var alphaBitmap = bitmap.Channels[Channel.Alpha];
    alphaBitmap.Save(@"Images\Output\Cmyk_test_Channel_A.tif");
}
```
 
### Splitting Channels with Pipelines
 
In printing it is not uncommon to handle large images. One of the major stages in offset printing is pre-press production, which includes converting an image to the proper CMYK color model and separating the image by colors. Pipelines offer a memory-friendly way of processing large images, including handling channels. The result of channels separation is a number of grayscale images that are used to create printing plates. The number of images depends on the source image color space. Graphics Mill provides the following classes, which allow the separation of images by channels:
 
- [RgbChannelSplitter](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelSplitter.htm.md) is specified to work with RGB images
- [CmykChannelSplitter](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_CmykChannelSplitter.htm.md) is specified to work with CMYK images
- [GrayscaleChannelSplitter](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleChannelSplitter.htm.md) is specified to work with grayscale images containing the alpha channel

The pixel format of the resulting image depends on the source image pixel format. The resulting image is [Format8bppGrayscale](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_PixelFormat_Format8bppGrayscale.htm.md) if the source bitmap is not extended, and [Format16bppGrayscale](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_PixelFormat_Format16bppGrayscale.htm.md) otherwise. Each splitter class also provides an ability to get the alpha channel.
 
The following code separates a CMYK image by color channels:
 
```csharp
using (var reader = new TiffReader(@"Images\cmyk.tif"))
using (var splitter = new CmykChannelSplitter())
{
    splitter.C = new TiffWriter(@"Images\Output\Cmyk_test_Channel_C.tif");
    splitter.M = new TiffWriter(@"Images\Output\Cmyk_test_Channel_M.tif");
    splitter.Y = new TiffWriter(@"Images\Output\Cmyk_test_Channel_Y.tif");
    splitter.K = new TiffWriter(@"Images\Output\Cmyk_test_Channel_K.tif");
    Pipeline.Run(reader + splitter);
}
```
 
## Writing Channels
  
### Replacing Channel
 
Some image editing operations require changing only one image channel (for example, the alpha channel). After the changes are completed, the source image channel should be replaced with the new one. In Graphics Mill you can easily replace a channel with a grayscale image through the **Bitmap.Channels** property.
 
**Important** 
A new channel must be of the same dimensions and resolution as the target image.
 
The following code replaces the cyan and alpha channels in a CMYK image with grayscale bitmaps:
 
```csharp
using (var bitmap = new Bitmap(@"Images\cmyk.tif"))
using (var cyanBitmap = new Bitmap(@"Images\Cmyk_test_Channel_C.tif"))
using (var alphaBitmap = new Bitmap(@"Images\Cmyk_test_Channel_A.tif"))
{
    bitmap.Channels[Channel.Cyan] = cyanBitmap;
    bitmap.Channels[Channel.Alpha] = alphaBitmap;
    bitmap.Save(@"Images\Output\Cmyk_test_cyan_alpha.tif");
}
```
 
### Merging Channels with Pipelines
 
Merging channels into a single image allows the creating of color images by combining several grayscale images. It is useful when, for example, you have 4 grayscale bitmaps prepared for printing (cyan, magenta, yellow, and black) and you need to make a color preview of the resulting image. The easiest way to merge channels into one image is to use one of the following combiner classes:
 
- [RgbChannelCombiner](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelCombiner.htm.md) is specified to work with RGB images
- [CmykChannelCombiner](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_CmykChannelCombiner.htm.md) is specified to work with CMYK images
- [GrayscaleChannelCombiner](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleChannelCombiner.htm.md) is specified to work with grayscale images containing the alpha channel

**Important** 
The merging channels must be of the same dimensions and resolution.
 
The following code creates a CMYK image by combining 4 grayscale bitmaps (one bitmap per color channel):
 
```csharp
using (var combiner = new CmykChannelCombiner())
using (var writer = new TiffWriter(@"Images\Output\Cmyk_test_combined.tif"))
{
    combiner.C = new TiffReader(@"Images\Cmyk_test_Channel_C.tif");
    combiner.M = new TiffReader(@"Images\Cmyk_test_Channel_M.tif");
    combiner.Y = new TiffReader(@"Images\Cmyk_test_Channel_Y.tif");
    combiner.K = new TiffReader(@"Images\Cmyk_test_Channel_K.tif");
    combiner.AutoDisposeSources = true;
    Pipeline.Run(combiner + writer);
}
```
 
## See Also
  
### Reference
 
- [Bitmap Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Bitmap.htm.md)
- [RgbChannelSplitter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelSplitter.htm.md)
- [CmykChannelSplitter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_CmykChannelSplitter.htm.md)
- [GrayscaleChannelSplitter Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleChannelSplitter.htm.md)
- [RgbChannelCombiner Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_RgbChannelCombiner.htm.md)
- [CmykChannelCombiner Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_CmykChannelCombiner.htm.md)
- [GrayscaleChannelCombiner Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleChannelCombiner.htm.md)

### Manual
 
- [Working with TIFF Extra Channels](https://www.graphicsmill.com/docs/gm/working-with-tiff-extra-channels.htm.md)
- [Accessing Pixel Data](https://www.graphicsmill.com/docs/gm/accessing-pixel-data.htm.md)
