Convert gray PNG to black and white TIF produces garbage output.

Jun 11, 2013 at 9:45 PM
I am new to ImageMagick (been using FreeImage) and I am trying to convert a bunch of grayscale PNG files to black and white (bi-tonal) tiffs. The code I have runs but produces tiffs that I can not open in anything, they are just garbage. Any help would be greatly appreciated. Here is what I got, it is C#:
public void convertPNGtoTiff(string workingFileName)
MagickImage PNGimage = new MagickImage(workingFileName);
PNGimage.QuantizeColorSpace = ColorSpace.GRAY;
PNGimage.QuantizeColors = 2;
PNGimage.QuantizeDither = true;
string newfilename = workingFileName.Substring(0, workingFileName.Length - 4) + ".tif";
Jun 12, 2013 at 4:33 AM
I think you should use the extension 'tiff' instead of 'tif'.
Jun 12, 2013 at 6:23 PM
Thanks for the reply. That made the outputted file 4 times larger, which looks more like the expected size, but I still can not open it with anything.
Jun 12, 2013 at 6:27 PM
Would you mind sharing one of your images so i can try to reproduce your problem.
Jun 12, 2013 at 7:25 PM
No problem, how do I get it to you? Also, I have been hacking at this and I found that if I save the output as a PNG it works fine, something about the tiff conversion is messing it up. I have also tried setting IsMonochrome = ture, it works faster and outputs an even bigger file but it is still no good.
Jun 12, 2013 at 7:48 PM
Have you tried loading the image after saving it? You will get some information about the image with MagickImage.ToString(). Can you share the image with some public service like '' or do you want to keep it private?
Jun 12, 2013 at 9:33 PM
I uploaded it to
Jun 12, 2013 at 10:09 PM
Edited Jun 12, 2013 at 10:18 PM
I tried your code and I seem to get the correct result:

It seems that the tiff I uploaded got converted to a png. If you contact me through codeplex (from my profile page) I will receive an email. I can send you a reply that includes the tiff I created.
Jun 12, 2013 at 10:26 PM
Now that makes this harder. Any idea what else could be wrong? Would it be helpful for me to email you the bad output I get for the same image and see if you can make heads or tails of what it is? Thanks again for all the help.
Jun 13, 2013 at 1:29 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 13, 2013 at 1:41 PM
The problem was the tiff compression that is being used. I created an issue to add the property that can be used to set the CompressionType.