Apply LZW Compression, Reduce Bit Depth, Reduce DPI for TIF, and Save as JPG

Oct 21, 2013 at 5:46 PM

I have been using the Magick.NET DLL in my projects, and am really quite impressed with the feature set!

I have several uncompressed TIF image files that are at a bit depth of 24 and a horizontal and vertical resolution of 300dpi. I would like to apply LZW compression, reduce the bit depth to 16 or even 8, reduce resolution to 300dpi, and save as JPG. Is this possible using the Magick.NET DLL?

Thank You.
Oct 21, 2013 at 6:06 PM
I am a bit confused by what you are asking. The LZW compression is only used to reduce the file size when you save your image as a TIF file. It has no affect when you convert a TIF file to JPG. The JPG file format uses a different compression. If you want to reduce the size of your JPG file you should use the Quality property. You can change the bit depth of your image with the Depth property. Changing the dpi from 300 to 300 must be a typo, the property you are looking for is Density.
using (MagickImage image = new MagickImage("input.tif"))
  image.Quality = 60;
  image.Depth = 8;
  image.Density = new MagickGeometry(150,150);
Oct 21, 2013 at 6:33 PM
Yes, I made a typing error. I intended to downgrade the dpi to 72. Thank you for educating me on LZW compression, I'm still learning some of the terminology and where it would apply. I think I might have an older version of the DLL, as Depth is a Method, and not a Property, of MagickImage. The Runtim Version registered in VS 2010 is v4.0.30319 and Version The DLL file's Date Modified is May 14, 2013. I'll try to download, install and reference the newest version.
Oct 21, 2013 at 7:19 PM
I downloaded and installed the latest Magick.NET-x64.DLL (copied to bin folder), and set my Debug configuration to x64. (I originally had x86.) I used your same exact code sample above, adding the ";" to the write statement. I got basically the same result as before: the JPG file's size did decrease substantially, but the bit depth and resolution did not change from the original TIF's. Could I send you the TIF file I'm working with, and/or the entire solution and output, see what I am doing wrong?
Oct 21, 2013 at 7:27 PM
Edited Oct 22, 2013 at 4:42 AM
Just send me the TIF you are working with. Contact me through CodePlex and I will reply so you have my e-mail address.

We continued our conversation by e-mail. The reason the bit depth was not changing was because bit-depth shown in windows explorer is 24 bit. The image is RGB with 8 bit channels, 3x8 = 24. And the density was not changing due to a profile that still reported 300dpi instead of 150dpi. Adding image.Strip() to the example above solved this.