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

Convert 32bit PNG to 8bit/128colors PNG

Aug 21, 2014 at 6:35 AM
Edited Aug 21, 2014 at 6:35 AM
hi all,

orig png: 32bit/96dpi
target png: 8bit/128colors/72dpi

my code so far:
using ImageMagick;
...
        using (MagickImage image = new MagickImage(origPATH))
        {
            image.Format = MagickFormat.Png;
            image.SetDefine(MagickFormat.Png, "colors", "128");
            image.SetDefine(MagickFormat.Png, "depth", "8");
            image.SetDefine(MagickFormat.Png, "resample", "72");

            image.Write(targetPATH);
        }
target png is written, but same as orig (32bit/96dpi)

please help
Coordinator
Aug 21, 2014 at 11:18 AM
Edited Aug 21, 2014 at 11:19 AM
You are calling the wrong methods. You hardly ever need to use the SetDefine method.
using (MagickImage image = new MagickImage(origPATH))
{
  image.Format = MagickFormat.Png;

  //image.SetDefine(MagickFormat.Png, "colors", "128");
  QuantizeSettings settings = new QuantizeSettings();
  settings.Colors = 128;
  image.Quantize(settings);

  //image.SetDefine(MagickFormat.Png, "depth", "8");
  image.Depth = 8;

  //image.SetDefine(MagickFormat.Png, "resample", "72");
  image.Resample(72, 72);

  image.Write(targetPATH);
}
Aug 21, 2014 at 11:37 AM
Edited Aug 21, 2014 at 11:37 AM
thanks...

but i want the target png in same dimensions with 72dpi

input : 445x600px
output: 56x72px
Coordinator
Aug 21, 2014 at 11:52 AM
You just want to set the DPI to 72? You can use the Density property for this.
Aug 21, 2014 at 11:58 AM
thats it, tnx