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

New Post: Converting from AI/SVG to PNG with transparent backgrounds.

$
0
0
It appears that you need to set the background color of the image when you write it. I missed that you were writing a PNG24 file instead of a PNG32 one. PNG24 only supports background transparency. The default background color is Transparent. When you change your code to my example below you will get the result that you want.
byte[] data = File.ReadAllBytes("67c49467-c9ed-4662-a4a6-08ed2c3536ce.svg");
using (var image = new MagickImage())
{
  MagickReadSettings settings = new MagickReadSettings()
  {
    Width = 600,
    Height = 600
  };

  image.Settings.BackgroundColor = new MagickColor("#FF00007F");
  image.Read(data, settings);

  image.BackgroundColor = new MagickColor("#FF00007F");
  image.Format = MagickFormat.Png24;
  image.Write("output.png");
}
I would advise you to specify the maximum size of your image when you read it instead of doing a resize. I am doing that in the example above.

I am going to change the behaviour in the next release of Magick.NET. Setting the MagickImage BackgroundColor will also set the Settings.BackgroundColor to make this more convenient. You can change your code to this then:
  image.BackgroundColor = new MagickColor("#FF00007F");
  image.Read(data, settings);

  image.Format = MagickFormat.Png24;
  image.Write("output.png");

Viewing all articles
Browse latest Browse all 3693

Trending Articles



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