Click here to Skip to main content
14,698,201 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My application contains a lot of large images (5mb+ Png or Jpeg format). The Images are used in various parts of the program and all are categorized in my own flat file database system. The Database itself only really supports text based entry, so whats stored in them is only the file name of the image like so: row1|Some various data|image1.png.

My problem is that the Images add about 100mb in size to my installed application (the application itself is only 1-2mb big with its included library's).

Is there a way that I can store these images and cut the size down? I know I could use an embedded database like SQLite, but I'd rather not if I can avoid it. I was thinking of Base64'ing the images and storing that in the my database itself but I've read that there is a 500kb limit to doing that.

I've looked into Archiving them and Unzipping them as needed but even then it only drops the total file size down 1 or 2 Megabytes.

Any ideas will help.

This[^] thread might also provide some options.
Sergey Alexandrovich Kryukov 11-Jan-11 11:14am
OK, good point - a 5.
Abhinav S 11-Jan-11 12:37pm
Thanks SAKryukov
Both PNG and JPEG formats are already well packed. Also, they are lossy (be very careful if you edit them: they will degrade; to edit pictures during development you may need to store them in a lostless format such as TIFF with ZIP or LZH compression)

PNG and JPEF are compressed much more effectively compared to ZIP or whatever non-specialized compressing method you may want to use.
This is because they PNG and JPEF allow some loss of data (there are lostless modes, far less common) and because they use methods specific to pixel graphic. For example, JPEG uses wavelet method (similar and related to Fourier transform).

By that reason, you will gain almost nothing if you try to compress already compressed PNG and JPEG. If you have non-compressed images like BMP or non-compressed TIFF (both not recommended), you may zip them, but the result will be much worse compared to... to what? to the same very JPEG and PNG...
Selection of best image file format and compression method is not trivial. It highly depends on graphical content, required resolution and even on how you present the picture and what you consider more important.

Base64 is a valid way to store any chunk of data. It will cost you extra 40% or so (easy to calculate how much exactly).

There is a good alternative to pixel graphics: vector graphics, but it works better for somewhat bigger picture sizes (perhaps not 16x16), especially if you want them scalable (very attractive feature). With WPF, it is very convenient to work with XAML (you can even draw in SVG and convert into XAML), otherwise WMF/EMF can be used (I did it, too, worked pretty well). XAML or SVG can be stored as text (they are XML-based); text can be compressed.

This is just the idea to consider. I think the detail of vector graphics is beyond the scope if this Question.
Espen Harlinn 11-Jan-11 11:02am
5+ Good answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900