Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: svg to png - transparent background

$
0
0
I have an svg. I want to create a png with c#.
It works fine but the only problem is transparency. The created png has always a white background.
If I open the original svg on a browser or in inkescape i see a transparent background.
Don't know if i must explicit transparency on svg source(in a specific way) or if i must use a particolar option in Magick.net library.

Thanks in advance for any tip.

This is my function:
private Stream convertSVG(Stream svgAsStream)
            {
                Stream convertedImage = new MemoryStream();

                using (MagickImage MGKimage = new MagickImage())
                {
                    //MGKimage.ColorAlpha(new MagickColor(255, 255, 255)); //alpha on white
                    //MGKimage.Alpha(AlphaOption.Background);

                    //set input image proprieties: SVG
                    MagickReadSettings mrs = new MagickReadSettings();
                    mrs.Format = MagickFormat.Svg;
                    mrs.ColorSpace = ColorSpace.Transparent;
                    
                    MGKimage.Read(svgAsStream, mrs);

                    //set output image proprieties: PNG
                    MGKimage.Format = MagickFormat.Png;
                    MGKimage.BackgroundColor = new MagickColor(System.Drawing.Color.Transparent);

                    MGKimage.Write(convertedImage);
                }

                return convertedImage;
            }

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>