Append TIFF Creates Black Pages
Posted: Tue Mar 12, 2024 4:01 pm
Hi,
We have upgraded one of our software applications to the new version of your product and are experiencing severe problems when appending pages from TIFF images into a multipage TIFF image.
When our software uses your product to append pages from one TIFF image to another, the first page (created when the new image is created in memory with TiffCreateMultiPageFromGdPictureImage) is OK, but all the subsequent pages are completely black.
Our version of the GdPicture (licensed) is: 14.2.65.0
Our application is built against .NET Framework 4.7.1, Any CPU, Prefer 32-bit.
The source image file formats affected by this problem are JPEG (in TIFF), (Grayscale or B&W), ZIP (in TIFF), Grayscale, Macintosh PackBits, Grayscale TIFF, and uncompressed TIFF images.
If the source images are TIFFs with LZW, Grayscale, all the pages, including the first one will be black in the resulting image file.
When a file with another compression is amongst the source files, the pages from that file are added into the resulting file in a correct way but others are black.
If the source image is duplicated by creating a new image in memory (with TiffCreateMultiPageFromGdPictureImage) and appending all source pages into the new image (with TiffSelectPage & TiffAppendPageFromGdPictureImage), the problem will also appear.
However, if the source image is just saved under another name (TiffCreateMultiPageFromFile then TiffSaveMultiPageToFile on using same handle) or if just the first page (created when the new image is created in memory with TiffCreateMultiPageFromGdPictureImage) is saved (with TiffSaveMultiPageToFile) under a different name, the problem will NOT appear.
If the source images are single page TIFFs, the problem will still appear.
If the source images were opened and saved within another software beforehand, such as IrfanView, the problem will still appear.
If there is just one source file and one of its pages is appended to the same file (TiffSelectPage any page and TiffAppendPageFromGdPictureImage to the same handle, then TiffSaveMultiPageToFile on the same handle), without ever creating a new image in memory, the appended page will still be black.
The short code to reproduce the problems:
We have upgraded one of our software applications to the new version of your product and are experiencing severe problems when appending pages from TIFF images into a multipage TIFF image.
When our software uses your product to append pages from one TIFF image to another, the first page (created when the new image is created in memory with TiffCreateMultiPageFromGdPictureImage) is OK, but all the subsequent pages are completely black.
Our version of the GdPicture (licensed) is: 14.2.65.0
Our application is built against .NET Framework 4.7.1, Any CPU, Prefer 32-bit.
The source image file formats affected by this problem are JPEG (in TIFF), (Grayscale or B&W), ZIP (in TIFF), Grayscale, Macintosh PackBits, Grayscale TIFF, and uncompressed TIFF images.
If the source images are TIFFs with LZW, Grayscale, all the pages, including the first one will be black in the resulting image file.
When a file with another compression is amongst the source files, the pages from that file are added into the resulting file in a correct way but others are black.
If the source image is duplicated by creating a new image in memory (with TiffCreateMultiPageFromGdPictureImage) and appending all source pages into the new image (with TiffSelectPage & TiffAppendPageFromGdPictureImage), the problem will also appear.
However, if the source image is just saved under another name (TiffCreateMultiPageFromFile then TiffSaveMultiPageToFile on using same handle) or if just the first page (created when the new image is created in memory with TiffCreateMultiPageFromGdPictureImage) is saved (with TiffSaveMultiPageToFile) under a different name, the problem will NOT appear.
If the source images are single page TIFFs, the problem will still appear.
If the source images were opened and saved within another software beforehand, such as IrfanView, the problem will still appear.
If there is just one source file and one of its pages is appended to the same file (TiffSelectPage any page and TiffAppendPageFromGdPictureImage to the same handle, then TiffSaveMultiPageToFile on the same handle), without ever creating a new image in memory, the appended page will still be black.
The short code to reproduce the problems:
Code: Select all
var multiPageImageOut = 0;
var newFileName = Path.ChangeExtension(selectedFilename, ".tmp");
var tiffCompression = TiffCompression.TiffCompressionUnknown;
using (var gdPictureImaging = new GdPictureImaging())
{
foreach (var filename in fileNames)
{
var multiPageImageIn = gdPictureImaging.TiffCreateMultiPageFromFile(filename, true);
if (tiffCompression == TiffCompression.TiffCompressionUnknown)
{
tiffCompression = gdPictureImaging.GetTiffCompression(multiPageImageIn);
}
var numberOfPages = gdPictureImaging.GetPageCount(multiPageImageIn);
var status = gdPictureImaging.TiffSelectPage(multiPageImageIn, 1);
if (multiPageImageOut == 0)
{
multiPageImageOut = gdPictureImaging.TiffCreateMultiPageFromGdPictureImage(multiPageImageIn);
}
else
{
status = gdPictureImaging.TiffSelectPage(multiPageImageIn, 1);
gdPictureImaging.TiffAppendPageFromGdPictureImage(multiPageImageOut, multiPageImageIn);
}
for (var i = 2; i <= numberOfPages; i++)
{
status = gdPictureImaging.TiffSelectPage(multiPageImageIn, i);
gdPictureImaging.TiffAppendPageFromGdPictureImage(multiPageImageOut, multiPageImageIn);
}
gdPictureImaging.ReleaseGdPictureImage(multiPageImageIn);
}
gdPictureImaging.TiffSaveMultiPageToFile(multiPageImageOut, newFileName, tiffCompression);
gdPictureImaging.ReleaseGdPictureImage(multiPageImageOut);
}
File.Move(newFileName, selectedFilename);
return selectedFilename;