I have been trying to reduce the size of the images that my code is creating/saving. In particular, we only work with documents and not images, so there is no need to save in 24 bit format. I just added code to convert to 8-bit by setting PixelFormat. But I am doing something wrong.
If I try to save the image to PDF, an AV occurs. However, saving the image as TIFF reveals there is definitely something I should be doing differently. See the attached TIFF. The relevant code is below. I have omitted some code for briefity. The actual code contains a loop that is loading multiple images from a collection of memory streams, which is why I am using TImageEnMIO.
var
mio: TImageEnMIO; // Holds all merged images/pages.
enView: TImageEnView; // Used to merge image & layers into single bitmap
begin
mio := TImageEnMIO.Create(nil);
try
enView := TImageEnView.Create(nil);
try
enView.ClearAll();
enView.IO.LoadFromStream(msStream);
enView.LayersMergeAll();
case enView.IEBitmap.PixelFormat of
ie16g,
ie24RGB,
ie32f,
ieCMYK,
ie48RGB,
ieCIELab,
ie32RGB: begin
enView.IEBitmap.PixelFormat := ie8p;
end;
end;
iIndex := mio.AttachedIEMBitmap.AppendImage;
mio.AttachedIEMBitmap.SetImage(iIndex, enView.IEBitmap);
mio.Params[0].TIFF_Compression:=ioTIFF_LZW;
mio.DuplicateCompressionInfo();
mio.SaveToStream(aStream, aFileType);
If it helps at all, here is the stack trace of the AV when saving as ioPDF:
System.Move(???,???,???)
imageenproc._CopyBGR_RGB($A6F9818,$11A9F728,2550)
iepdf.TIEPDFBuilder.AddImage(0,0,612,792,$A3622B0,0,1,$A287950,$25EF6DC)
iepdf.TIEPDFBuilder.AddPageWithImage($A3622B0,$A287950,$25EF6DC)
iepdf.TIEPDFBuilder.AddPageWithImage($A3622B0,$A287950)
iemio._SaveImg(0,0)
iemio.TImageEnMIO.SaveToStreamPDF($A274AC8,False)
iemio.TImageEnMIO.SaveToStream($A274AC8,18,False)
Thank you for any assistance provided! :-)
Edit: I neglected to attach the image earlier.
attach/JonMRobertson/2023818141136_TestImage.tiff