简体   繁体   中英

How can I store lots of images in a single file for a WinForms app?

I have a .net WinForms 2.0 application that has an image library of about 3000 images currently. Currently I'm using SQLite and storing all of the images as BLOBs with a unique Ids that makes things easy to retrieve.

The benefit to this is that the end users don't have to worry about the installer unzipping a massive blob of images on their computer, and when updates are made, I can push out a single file for the users download that is a fresh copy of everything. The files to tend to be rather large (currently ~60 meg.), but the end users are used to it and the application also has a "no image" mode for those on dial-up.

The one downside to all of this is that generating the library can be a little tricky at times. The data has to get converted into the binary format, I have to make sure the corresponding Ids are properly linked. The job that generates the library takes a while to run as well.

I'm in the process of upgrading the application and I'm wondering if there is a better approach to doing this. I'd still like to keep the single file approach for ease in sending updates to users and keeping the footprint on the computer smaller. Is there some kind of "portable filesystem" or resource library that I can use/create that would allow me to easily insert/retrieve images from it without necessarily having a database for the application to interact with?

A resx file (compiled to a resource dll)? Or simpler - a zip file? Perhaps using #ZipLib.

7zip also have a library you could use also, see this

Also you could move the images to be served off a web server and have the client cache the image locally, and then have a way of the client checking for an updated image periodically, that way only the required images would have to be downloaded.

You could also have lo-res versions for dial-up users.

I've used the ImageList control and AddStrip methods in similar situations. I then have one giant PNG file that contains all the images. This is great for icons but won't work well for other types of resources.

Depending on your circumstances, a custom ISAM type file is a possibility.

The overall file layout would be:

----------------
| Count  | int |
----------------
| Index  |
----------
| Images |
----------

Index format

----------------
| offset | int |
----------------
| size   | int |
---------------------------
| description  | char(50) |
---------------------------
|  id    | int |
----------------

The count would be an integer containing the number of images in the file. The index would contain (offset, size) pairs describing the offset into the file to seek to and the number of bytes to read beginning at that offset.

A downside to this format is that replacing an existing picture would require rebuilding the file.

Fixed length metadata like descriptions and ID's could be placed in the header.

(Perhaps one upside to this method of madness is the speed of access if you are holding the index in RAM.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM