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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnIO.SaveToFileZIP?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

943 Posts

Posted - Feb 02 2025 :  04:36:40  Show Profile  Reply
The existing method TImageEnIO.LoadFromFileZIP loads an image from a ZIP file into the attached TImageEnView or TIEBitmap using a plug-in.

AFAIK, there is no REVERSE function TImageEnIO.SaveToFileZIP using the same plugin. I need this function to:
1. Load an image from ZIP in TImageEnView using TImageEnIO.LoadFromFileZIP
2. Edit the image in TImageEnView
3. Save the image back to the same ZIP file using TImageEnIO.SaveToFileZIP (including CompressionLevel parameter from 0=Store to 9=Maximum)

Could you implement this?

This would save me from having to save the image to a temporary file first and then add that temporary file to the ZIP using TZip methods.

PeterPanino

943 Posts

Posted - Feb 02 2025 :  12:07:44  Show Profile  Reply
In the meantime, I've implemented a routine that uses TZipFile to save the image in the ZIP file:

procedure SaveImageInZip(AIO: TImageEnIO; const AImageName, AZipFile: string; AFileType: TIOFileType = hyieutils.ioUnknown);
var
  Zip: TZipFile;
  Stream: TMemoryStream;
  ZipPath: string;
  ExistingIndex: Integer;
begin
  Stream := TMemoryStream.Create;
  try
    // Save the image to the stream using the specified or determined file type
    AIO.SaveToStream(Stream, AFileType);
    Stream.Position := 0; // Reset stream position to beginning

    // Ensure the target directory exists
    ZipPath := ExtractFilePath(AZipFile);
    if ZipPath <> '' then
      ForceDirectories(ZipPath);

    // Add the stream to the zip file
    Zip := TZipFile.Create;
    try
      // Handle existing zip files
      if FileExists(AZipFile) then
      begin
        Zip.Open(AZipFile, TZipMode.zmReadWrite);

        // Delete existing entry if it exists
        ExistingIndex := Zip.IndexOf(AImageName);
        if ExistingIndex >= 0 then
          Zip.Delete(ExistingIndex);
      end
      else
        Zip.Open(AZipFile, TZipMode.zmWrite);

      // Add with STORE compression (no compression)
      Zip.Add(Stream, AImageName, TZipCompression.zcStored);
      Zip.Close;
    finally
      Zip.Free;
    end;
  finally
    Stream.Free;
  end;
end;
Go to Top of Page

xequte

38754 Posts

Posted - Feb 02 2025 :  19:29:22  Show Profile  Reply
Thanks for posting that, Peter. How much larger was the EXE file size after adding the zip unit to your project?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

943 Posts

Posted - Feb 03 2025 :  10:40:11  Show Profile  Reply
That's not relevant. However, for the sake of simplicity and completeness, a TImageEnIO.SaveToFileZIP method would be nice.
Go to Top of Page

xequte

38754 Posts

Posted - Feb 03 2025 :  16:29:24  Show Profile  Reply
Yes, it is on the to-do list.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: