---
title: "Remove a plain background around a logo"
canonical: https://www.graphicsmill.com/samples/Transforms/BackgroundRemoval/RemoveContiguousBackground_cs
product: "Graphics Mill"
source: "Transforms/BackgroundRemoval/RemoveContiguousBackground.cs"
---

# Remove a plain background around a logo

This sample shows how to make the background of a logo or a product shot transparent with the ` ContiguousBackgroundRemoval ` transform. The background is everything that can be reached from the border of the image through pixels of similar colour, so areas of the same colour that the subject encloses stay opaque: the white letters on the badge are kept, while a colour key such as ` Transparentize ` would punch them out too. The background colour is detected automatically from the border of the image.

## Instruction

Use the Bitmap API to remove the plain white background around a JPEG logo with the RemoveContiguousBackground transform, keeping the white areas inside the logo, and save the result with transparency as PNG.

## Code Snippet

```csharp
using (var bitmap = new Bitmap("Badge.jpg"))
{
    // The background colour is the median colour of the border, white here.
    bitmap.Transforms.RemoveContiguousBackground();

    bitmap.Save("RemoveContiguousBackground.png");
}
```

## Explanation

The code:

- Loads the JPEG logo "Badge.jpg" into a ` Bitmap `.
- Calls ` Bitmap.Transforms.RemoveContiguousBackground `, which detects the background colour from the border of the image and makes every pixel connected to the border through similar colours transparent.
- Keeps the white letters inside the badge opaque, because the badge separates them from the background around it.
- Saves the result, now with an alpha channel, to "RemoveContiguousBackground.png".

## Tags

- [Background Removal](<https://www.graphicsmill.com/samples/tags/background-removal_md>): Making the background around a subject transparent
- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Transform](<https://www.graphicsmill.com/samples/tags/transform_md>): Image transforms and effects
- [Transparentize](<https://www.graphicsmill.com/samples/tags/transparentize_md>): Making pixels transparent with transforms

## Input

- [Badge.jpg](<https://www.graphicsmill.com/samples/Transforms/compiled/Debug/Badge_jpg>) (preview)

## Output

- [RemoveContiguousBackground.png](<https://www.graphicsmill.com/samples/Transforms/compiled/Debug/RemoveContiguousBackground_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.Transforms](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.RemoveContiguousBackground](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_RemoveContiguousBackground.htm.md>)
