I have tried to create a workaround by first extracting the image file to a stream and then loading the image in TImageEnIO with LoadFromStream. However, in some cases, this inexplicably fails:
// Extracts AZipEntryName from the ZIP at AZipFilePath (even if it has a non-standard extension) into AIO (TImageEnIO).
// Returns True if the image is successfully loaded into AIO (TImageEnIO), False otherwise.
function LoadFileFromZipToTImageEnIO(const AZipFilePath, AZipEntryName: string; AIO: TImageEnIO): Boolean;
var
LZipFile: TZipFile;
LStream: TStream;
LLocalHeader: TZipHeader;
begin
Result := False;
LZipFile := TZipFile.Create;
try
try
// Open the ZIP from disk in read mode
LZipFile.Open(AZipFilePath, zmRead);
// Create a memory stream to hold the uncompressed file data
LStream := TMemoryStream.Create;
try
// Extract AZipEntryName into LStream
CodeSite.Send('LoadFileFromZipToTImageEnIO: BEFORE LZipFile.Read AZipEntryName', AZipEntryName);
LZipFile.Read(AZipEntryName, LStream, LLocalHeader);
CodeSite.Send('LoadFileFromZipToTImageEnIO: AFTER LZipFile.Read');
// Reset position to the start of the uncompressed data
LStream.Position := 0;
// Feed the uncompressed data to ImageEn
var LoadFromStreamSuccess := AIO.LoadFromStream(LStream); // in some cases this inexplicably fails!
CodeSite.Send('LoadFileFromZipToTImageEnIO: LoadFromStreamSuccess', LoadFromStreamSuccess);
if LoadFromStreamSuccess then
Result := True;
finally
LStream.Free;
end;
except
// Todo: log error
end;
finally
LZipFile.Free;
end;
end;