This project has moved. For the latest updates, please go here.

SVG to transparent PNG

Oct 15, 2015 at 6:53 AM
hi,
i'm trying to convert svg to transparent png.
        var url = "J:/MyGit/ImagePlayground/ImagePlayground/bin/Debug/mask.svg";
        var image = new MagickImage(url);
        image.Format=MagickFormat.Png24;
        image.Write("mask.png");
but the resulted image, has white background.
how do i keep the transparency of the result ?

thanks
juna
Coordinator
Oct 15, 2015 at 11:02 AM
Can you post a link to your .svg file here?
Coordinator
Oct 16, 2015 at 7:55 PM
It is most likely that your svg contains a white 'fill' color. You can fix this by removing that fill color form the file with a text editor. You could also automate this.
Oct 23, 2015 at 7:28 AM
all of my converted svg files have white background where it should be transparent.
sample
www.cottoncapitol.com/media/eagle.svg
result :
www.cottoncapitol.com/media/eagle-magick.png

here's what i do :
        var img = new MagickImage("J:/MyGit/ImagePlayground/ImagePlayground/bin/Debug/eagle.svg");
        img.Write("J:/MyGit/ImagePlayground/ImagePlayground/bin/Debug/eagle-magick.png");
Coordinator
Oct 23, 2015 at 10:57 AM
You are getting a white background because that is the default background color. If you specify it before you read the image you can overrule the default. Below is an example:
using (var img = new MagickImage())
{
  img.BackgroundColor = MagickColor.Transparent;
  img.Read("J:/MyGit/ImagePlayground/ImagePlayground/bin/Debug/eagle.svg");
  img.Write("J:/MyGit/ImagePlayground/ImagePlayground/bin/Debug/eagle-magick.png");
}
Oct 24, 2015 at 7:27 AM
i had always pass the image path in magickimage constructor.
so that's why i always get white background.

thanks for your reply, it really helps.