ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnIO.LoadFromFileZIP issue

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Jan 26 2025 : 05:13:37
TImageEnIO.LoadFromFileZIP generally works well. However, in a special case, if the ZIP FILE (and it is a ZIP file) has an extension other than .zip (e.g. .ZIPXY), LoadFromFileZIP fails.

It would be helpful if LoadFromFileZIP could also work in such corner cases (when the zip file has a different extension)!
2   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jan 26 2025 : 13:04:05
Hi Peter

The archive file must have a supported extension: *.zip, *.zipx, *.epub, *.7z, *.bzip2, *.bz2, *.gzip, *.cab, *.rar, *.tar, *.iso, *.chm, *.lzh

I will update the documentation.


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Jan 26 2025 : 12:52:16
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;