views:

2474

answers:

3

I have a large number of TIFF images that I’d need to use in a WPF program (.NET 3.5 SP1 specifically and using C#). Half of the TIFF files contain color images encoded using JPEG compression and they don’t work with WPF. The “Microsoft Office Document Imaging” application handles the files fine. As Windows itself doesn’t really like them either (can’t produce thumbnails for instance) I’m assuming this is a restriction in the standard Windows Imaging Components (WIC) libraries.

Does anyone have any ideas on how to correctly read the TIFF images that are using JPEG compression with the standard .NET/WPF libraries?

Or does anyone know of any alternate third party TIFF codecs for WIC that I might be able to use to work around this issue?

Or finally are there any alternate .NET libraries for TIFF files that are still easily usable with WPF?

Thanks!

+1  A: 

TIFF-wrapped JPEGs come in two flavors - type 6 and type 7. What you are describing are the type 6 TIFFs. While Adobe has recommended for years that this type not be used (see Tech Note 2 for details), several graphics packages still use it.

I know of a few commercial graphics packages for .NET that can read them such as the Captiva ISIS PixTools (formerly Pixtran) libraries, but do not know offhand of anything open source or otherwise free.

DocMax
Actually they are type 7 files (they're created by a Win32 application we wrote and I checked the source). Microsoft Office Document Imaging opens them fine, but other Microsoft tools can't handle them (e.g. Paint or Windows Picture and Fax Viewer.
Scott Bussinger
A: 

What WPF API are you using to handle them?

Have you tried using TiffBitmapDecoder from the System.Windows.Media.Imaging namespace?

arul
I'd been simply trying to use an Image component. I tried the sample code from the MSDN article you suggested and while it works for other files, the JPEG compressed images all generate 0x88982F40 exceptions when attempting to decode the file.
Scott Bussinger
A: 

I was wondering if a solution was ever figured out for this issue. Were you able to get these outdated TIFFs to load properly?

I think that with some tweaking you can get ImageMagick to read these files in. It's open source

Mike
I finally had to punt and take a different approach to the problem. Ultimtely I dropped support for multi-page images like TIFF files and split them out into multiple separate images using JPG or PNG encoding (depending on the contents).The latest WIC libraries in Windows 7 worked fine with the JPG encoded images, but they weren't ported back to WinXP so I finally wrote my own custom converter to do the heavy lifting (I'd had Delphi libraries to handle them).This approach wasn't ideal and probably not an option for many people, but it was OK in our situation.
Scott Bussinger