How to load JPEG images from ZIP archive? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

How to load JPEG images from ZIP archive?

Post by Tapsa »

I want to load images into wxImage from ZIP files.
So far I have made this code:

Code: Select all

wxDirDialog dialog(this, "Folder containing ZIPs");
if(dialog.ShowModal() == wxID_OK)
{
    wxDir::GetAllFiles(dialog.GetPath(), &zips, "*.zip");
    std::unique_ptr<wxZipEntry> entry;
    wxFFileInputStream trash(zips[0]);
    wxZipInputStream zip(trash);
    entry.reset(zip.GetNextEntry());
    if(entry.get())
    {
        wxImage pic(entry->MagicalStream(), wxBITMAP_TYPE_JPEG);
    }
}
What is the fastest method to load an image from a ZIP file? I intend to only display the images. I am doing an image viewer that can show images from ZIP files and browse between ZIP files in the same folder.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to load JPEG images from ZIP archive?

Post by doublemax »

The code looks ok. Just replace "entry->MagicalStream()" with the wxZipInputStream "zip" and it should work.
Use the source, Luke!
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: How to load JPEG images from ZIP archive?

Post by Tapsa »

Thanks. Such simple solution.
Post Reply