1

My program, that converts a multi page TIFF to PDF is not longer working under Windows 7. The program contains code that walks through the pages of the TIFF, converts each page as TIFF with CCITT Group4 compression and inserts the bitmap data in the resulting PDF file.

Converting is done in the following way (c#):

 ImageCodecInfo tiffCodecInfo = GetEncoderInfo("image/tiff");
 EncoderParameters myEncoderParameters = new EncoderParameters(2);

 // Save the bitmap as a TIFF file with CCITT group4 compression.       
 myEncoderParameters.Param[0] = new EncoderParameter System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue..CompressionCCITT4);
 myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 1L);
 image.Save(source, tiffCodecInfo, myEncoderParameters);

It seems that the behaviour of GDI+ is changed in Windows 7: The resulting CCITT bitmap data is no longer encoded in a single strip. Because of this I cannot use this bitmap data in my PDF file.

Question: does anybody know how I can tell GDI+ to encode the bitmap data in a single strip?

Corne
  • 646
  • 1
  • 6
  • 19

2 Answers2

1

I received an answer from Microsoft:

Yes, in Windows 7 we did extensive work to the TIFF CODEC. One of the pieces of work was to support decoding and encoding in multiple strips. Unfortunately there is no way to control the number of strips outputted by the encoder.

Corne
  • 646
  • 1
  • 6
  • 19
  • Doen anybody by a chance know how to convert multi strip CCITT G4 data to a single strip? – Corne Aug 18 '09 at 07:16
  • I don't know anything about GDI+, but I've written C code which can do what you need. It will convert the multi-strip G4 image into a compact run-length encoded format and then re-encode it as G4 in a single strip. Let me know if I can help. bitbank@pobox.com – BitBank Aug 20 '09 at 08:06
1

The short answer is that: If you want to stay with GDI+ (or its .NET counterpart System.Drawing.Imaging), you'll be subjected to its limitations. This is because Microsoft controls its implementation, and it is their decision not to implement certain features or customization points or to do certain tasks in a particular way.

Therefore my answer to that is to use an alternative, such as Windows Imaging Component (WIC, or its .NET counterpart System.Windows.Media.Imaging, found in PresentationCore).

Note that the .NET implementation (wrapper) of WIC has some crippling issues, such as not being fully thread-safe. (It may be sufficient for hobby and consumer applications, not for production-grade server-side applications.)

This is one reason I suggest using a .NET library for TIFF that isn't dependent on PresentationCore.

http://bitmiracle.com/libtiff/

See also: Using LibTiff from C# (to access tiled TIFF images)

rwong
  • 6,062
  • 1
  • 23
  • 51
  • LibTiff 2.0 (just released) ships with samples and one of them shows how to convert any non-tiled TIFF image to the TIFF image which have all data written in a single strip. – Bobrovsky Aug 04 '10 at 06:12
  • @Chris done. I've explained my rationale. The sole purpose of linking is to point readers to the alternative choices of third-party library. I don't have anything to quote from those links. – rwong Jun 04 '21 at 03:40