10,000 PNG files!

Started by
12 comments, last by Dave Haylett 6 years, 1 month ago

Hi Kylotan. I did briefly look around for options, ideally I’d need I) a front-end to allow me to easily load in new PNGs to the archive, and II) hopefully a NuGet package with functions which would allow me to pull the data through at runtime. Brain suggested PhysicsFS which sounded like a good alternative but unfortunately I couldn’t get it to work in VS2015 and the package seems a bit archaic (read C++). I did consider writing the above image packer in VBA but if anyone can think of alternatives I’d love to hear them.

Advertisement

DotNetZip and Windows Explorer to create the zip files? There must be tons of libraries to handle the zip format.

On 21/02/2018 at 3:12 PM, Kylotan said:

DotNetZip and Windows Explorer to create the zip files? There must be tons of libraries to handle the zip format.

Hmm ok so I'm trying DotNetZip. If I were to zip all my images up into a single file, then add that zip as a resource to my project, what I'm trying to do now is extract a single file from that zip into a MemoryStream, so I'm not touching the HDD at all, and then convert from the MemoryStream to a WriteableBitmap.

Annoyingly DotNetZip doesn't appear to have the functionality to extract a single file from the zip directly to a MemoryStream. I can extract a single entry from the collection of all entries to a MemoryStream using foreach, but I don't want to have to foreach through 10,000 records until I find the filename I want each time I want to extract a single entry  :/

Any ideas? I feel like I'm making this harder work than it should be :(

 

EDIT: further googling has revealed that with DotNetZip I can simply go:   archive["filename.png"]! So my code now looks like this, and appears to work!:


        MemoryStream zipMs = new MemoryStream();
            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.MyResourceFiles.MyArchive.zip");

            using (ZipFile zip = ZipFile.Read(stream))
            {
                ZipEntry entry = zip["MyImage.png"];
                entry.Extract(zipMs);
                BitmapImage biImg = new BitmapImage();
                biImg.BeginInit();
                biImg.StreamSource = zipMs;
                biImg.EndInit();
                return new WriteableBitmap(biImg);
            }

 

EDIT 2: The above was way too slow, even if I rezipped the PNGs using 7zip as just Store (i.e. no further compression), however the culprit was the ZipFile.Read() line, and so I've moved this into my initialisation process and made it global. Now works like a dream! I've added a Zipfile.Dispose upon close.

This topic is closed to new replies.

Advertisement