Converting EMF to PNG

Dec 20, 2013 at 10:56 AM
Hello,

Could anyone please help me to achieve below conversion using magic.net

convert -density 288 image.emf -flatten -quality 00 -colorspace RGB -resize 50% -colorspace sRGB image.png

I am a newbie to imagemagick and magick.net, not familiar with magic.net API, I am finding it difficult to do the above conversion.

Thanks!
Coordinator
Dec 20, 2013 at 6:26 PM
At this moment you need an external executable called emfplus.exe (http://www.imagemagick.org/download/contrib/EMFPlus.tar.gz) in your bin directory. I am working on trying to integrate this within ImageMagick but I cannot give you an ETA when this will be done. Your example above can be rewritten like this:
  MagickReadSettings settings = new MagickReadSettings();
  settings.Density = new MagickGeometry(288, 288);
  using (MagickImageCollection images = new MagickImageCollection("image.emf", settings))
  {
    using (MagickImage image = images.Flatten())
    {
      image.Quality = 100; // You are missing a 1?
      image.ColorSpace = ColorSpace.RGB;
      image.Resize(0.5); // implicit cast to Percentage
      image.ColorSpace = ColorSpace.sRGB;
      image.Write("image.png");
    }
  }
Dec 21, 2013 at 2:57 AM
Thanks for your quick reply.

For quality - I was trying to do it as it's mentioned in docs http://www.imagemagick.org/Usage/formats/#png . Did I get it wrong?
PNG compression

When used with PNG output, quality is regarded as two decimal figures. The first digit (tens) is the zlib compression level, 1-9. However if a setting of '0' is used you will get Huffman compression rather than 'zlib' compression, which is often better! Weird but true!
The second digit is the PNG data encoding filtering (before it is comressed) type: 0 is none, 1 is "sub", 2 is "up", 3 is "average", 4 is "Paeth", and 5 is "adaptive". So for images with solid sequences of color a "none" filter (-quality 00) is typically better. For images of natural landscapes an "adaptive" filtering (-quality 05) is generally better.
Coordinator
Dec 21, 2013 at 8:07 AM
If you want to specify it like that you need to use the SetDefine method in Magick.NET:
  using (MagickImage image = images.Flatten())
  {
    image.ColorSpace = ColorSpace.RGB;
    image.Resize(0.5); // implicit cast to Percentage
    image.ColorSpace = ColorSpace.sRGB;
    image.SetDefine(MagickFormat.Png, "compression-strategy", "0");
    image.SetDefine(MagickFormat.Png, "compression-filter", "0");
    image.Write("image.png");
  }
Dec 22, 2013 at 5:34 AM
Thanks again for your help.