Remove a plain background around a logo
View as MarkdownThis 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.
Code Snippet
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");
}
Input
Badge.jpg
Output
RemoveContiguousBackground.png