---
title: "Convert To Indexed"
canonical: https://www.graphicsmill.com/samples/ColorManagement/ConvertingPixelFormats/ConvertToIndexed_cs
product: "Graphics Mill"
source: "ColorManagement/ConvertingPixelFormats/ConvertToIndexed.cs"
---

# Convert To Indexed

Converts to indexed pixel format (optimized for Web).

## Instruction

Converts an RGB image to an 8-bit indexed color format using dithering and custom color palette.

## Usings

```csharp
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
using (var bitmap = new Bitmap("Copenhagen_RGB.jpg"))
{
    bitmap.ColorManagement.Dithering = DitheringType.FloydSteinberg;
    bitmap.ColorManagement.Palette = ColorPalette.Create(bitmap, 64);
    bitmap.ColorManagement.Convert(PixelFormat.Format8bppIndexed);

    bitmap.Save("PF_ConvertToIndexed.png");
}
```

## Explanation

The code:

- Loads the "Copenhagen_RGB.jpg" image using the `Bitmap` class.
- Applies Floyd-Steinberg dithering (`DitheringType.FloydSteinberg`) and generates a custom 64-color palette (`ColorPalette.Create`).
- Converts the image to an 8-bit indexed format (`PixelFormat.Format8bppIndexed`) using color management.
- Saves the converted image as a PNG file ("PF_ConvertToIndexed.png") using the `Save` method.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Color Conversion](<https://www.graphicsmill.com/samples/tags/color-conversion_md>): Converting colors between color spaces
- [Indexed format](<https://www.graphicsmill.com/samples/tags/indexed_md>): Working with indexed-color images

## Input

- [Copenhagen\_RGB.jpg](<https://www.graphicsmill.com/samples/ColorManagement/compiled/Debug/Copenhagen_RGB_jpg>) (preview)

## Output

- [PF\_ConvertToIndexed.png](<https://www.graphicsmill.com/samples/ColorManagement/compiled/Debug/PF_ConvertToIndexed_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.ColorManagement](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorManagement.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorManagementProvider_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Dithering](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_ColorManagementProvider_Dithering.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Palette](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_ColorManagementProvider_Palette.htm.md>)
- [Aurigma.GraphicsMill.ColorPalette](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorPalette.htm.md>)
- [Aurigma.GraphicsMill.ColorPalette.Create(Bitmap,Int32)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorPalette_Create_2_95bfa618.htm.md>)
- [Aurigma.GraphicsMill.Transforms.DitheringType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_DitheringType.htm.md>)
