---
title: "How to: Use a Color Remap Table"
ms.date: "03/30/2017"
dev_langs: 
  - "csharp"
  - "vb"
helpviewer_keywords: 
  - "color tables [Windows Forms], remapping colors with"
  - "custom colors [Windows Forms], creating with color remap table"
  - "color remap tables [Windows Forms], using"
ms.assetid: 977df1ce-8665-42d4-9fb1-ef7f0ff63419
---
# How to: Use a Color Remap Table
Remapping is the process of converting the colors in an image according to a color remap table. The color remap table is an array of <xref:System.Drawing.Imaging.ColorMap> objects. Each <xref:System.Drawing.Imaging.ColorMap> object in the array has an <xref:System.Drawing.Imaging.ColorMap.OldColor%2A> property and a <xref:System.Drawing.Imaging.ColorMap.NewColor%2A> property.  
  
 When GDI+ draws an image, each pixel of the image is compared to the array of old colors. If a pixel's color matches an old color, its color is changed to the corresponding new color. The colors are changed only for rendering — the color values of the image itself (stored in an <xref:System.Drawing.Image> or <xref:System.Drawing.Bitmap> object) are not changed.  
  
 To draw a remapped image, initialize an array of <xref:System.Drawing.Imaging.ColorMap> objects. Pass that array to the <xref:System.Drawing.Imaging.ImageAttributes.SetRemapTable%2A> method of an <xref:System.Drawing.Imaging.ImageAttributes> object, and then pass the <xref:System.Drawing.Imaging.ImageAttributes> object to the <xref:System.Drawing.Graphics.DrawImage%2A> method of a <xref:System.Drawing.Graphics> object.  
  
## Example  
 The following example creates an <xref:System.Drawing.Image> object from the file RemapInput.bmp. The code creates a color remap table that consists of a single <xref:System.Drawing.Imaging.ColorMap> object. The <xref:System.Drawing.Imaging.ColorMap.OldColor%2A> property of the `ColorRemap` object is red, and the <xref:System.Drawing.Imaging.ColorMap.NewColor%2A> property is blue. The image is drawn once without remapping and once with remapping. The remapping process changes all the red pixels to blue.  
  
 The following illustration shows the original image on the left and the remapped image on the right.  
  
 ![Screenshot showing the original image and the remapped image.](./media/how-to-use-a-color-remap-table/original-image-remap-colors.png)  
  
 [!code-csharp[System.Drawing.RecoloringImages#31](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.RecoloringImages/CS/Class1.cs#31)]
 [!code-vb[System.Drawing.RecoloringImages#31](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.RecoloringImages/VB/Class1.vb#31)]  
  
## Compiling the Code  
 The preceding example is designed for use with Windows Forms, and it requires <xref:System.Windows.Forms.PaintEventArgs> `e`, which is a parameter of the <xref:System.Windows.Forms.Control.Paint> event handler.  
  
## See also

- [Recoloring Images](recoloring-images.md)
- [Images, Bitmaps, and Metafiles](images-bitmaps-and-metafiles.md)
