In a Delphi (11.3) VCL program, I'm trying to create a multi-page TIFF file from individual TIFF pages. At first, I was able to successfully combine all the individual TIFF's into one TIFF, but the pages just overlayed each other, and it was only 1 page. I want to output 1 TIFF with more than one page. So the output file path is valid and writable and the file is not locked by another user. Here's the code:
procedure TiffsToMultiPage(const fileNames: array of string; const outputFileName: string);
var
multiPageBitmap: TBitmap;
wicImage: TWICImage;
i: Integer;
begin
// Initialize the bitmap
multiPageBitmap := TBitmap.Create;
try
// Load and combine the images
for i := 0 to High(fileNames) do
begin
wicImage := TWICImage.Create;
try
wicImage.LoadFromFile(fileNames[i]);
multiPageBitmap.Canvas.Draw(0, i * wicImage.Height, wicImage);
finally
wicImage.Free;
end;
end;
// Output the multi-page TIFF
multiPageBitmap.SaveToFile(outputFileName);
finally
multiPageBitmap.Free;
end;
end;
When I click the Enter button one TIFF file gets output, but the file is empty (zero bytes).
procedure Tfrm_Main.btn_EnterClick(Sender: TObject);
begin
// Combine the TIFF's
TiffsToMultiPage(['file1.tif', 'file2.tif', 'file3.tif'], 'C:\Documents\Test\combined_multi_page.tif');
end;
I have verified file paths, inspected variables, debugged to make sure that each image gets loaded, and added a breakpoint to step through the code to identify any issues. Why is this code outputting a zero-byte file?
multiPageBitmap
before you start to load the images into it. E.g.multiPageBitmap.SetSize(w, n * h)
copy/b file1.tif+file2.tif+file3.tif combined_multi_page.tif
TBitmap
does not support TIFF images. You are actually creating a BMP image with a.tif
file extension. BMP and TIFF are very different formats