This project has moved and is read-only. For the latest updates, please go here.

Make white background transparent on existing PNG

Oct 21, 2014 at 6:19 PM
Hello, I saw some previous discussions regarding transparency on PNGs, specifically, this thread
https://magick.codeplex.com/discussions/453564

Given an existing PNG image, I would like to make the white background transparent. Does the code in the above discussion make this possible?

Thanks in advance
Oct 23, 2014 at 1:41 PM
That example is about making an image larger and setting the new pixels to transparent. Do you want to change every white pixel to transparent or do you want ImageMagick to detect the background and change that to transparent?
Oct 23, 2014 at 2:51 PM
Thanks for your reply. I am interested in turning every white pixel transparent. That seems simpler than detecting a background.
Oct 23, 2014 at 5:04 PM
I'm very much interested in doing this as well.
Oct 23, 2014 at 6:50 PM
You can change all the white pixels with the following method:
using (MagickImage image = new MagickImage(@"C:\input.png"))
{
  image.Opaque(new MagickColor("white"), MagickColor.Transparent);
  image.Write(@C:\output.png");
}
Oct 23, 2014 at 7:03 PM
Thanks for the code example. I will give it a spin and report back.
Oct 23, 2014 at 7:29 PM
worked great! thanks