Page 1 of 1

Multiple images in one file

Posted: Sun Apr 18, 2010 10:03 am
by omit59
Anybody having an example how to save and load multiple images in same file?

Timo

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 10:12 am
by srod
The simplest way would be to use the packer library etc.

Beyond this and I have (for the nxReport reporting library) created single files containing mutliple images (+ a whole load of other stuff). The images were all saved in 24-bit BMP format for which I just used some api code to manually create the BMP file in memory and then write to the disk file etc. Of course, if you require your images to be in a mixture of formats (BMPs, PNGs etc.) then this would make things a little more complex. The important thing is that the file you create must contain some additional information to allow you to pull out the respective images. Create a file header which contains a count of the number of images followed by an array of pointers to the first byte of each image etc.

But again, the simplest way would be to perhaps use a pack file. :)

Another alternative is an OLE compound document -something which I have been meaning to get around to. If I get some time this week I might create a simple wrapper for this.

Consider also using an SQLite database.

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 10:44 am
by Kaeru Gaman
also consider using Windows Ressources, to put all Images you need into your EXE.

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 11:08 am
by srod
Depends on what his intentions are of course? If he is creating some kind of dynamic document for use with some application or other then a resource section is out.

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 12:20 pm
by Kaeru Gaman
sure.
I just wanted to mention this additional option if he wanted to create an archive to come with his exe.

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 5:17 pm
by omit59
Thanks for the reply, srod and Kaeru Gaman

Yes, I have started using Packer lib for this, and also thinking about using database file, but never used Sqlite, so it's totally new to me...

I was thinking of something like srod wrote about creating image in memory and then writing it to the disk.
Images will be loaded from file or created from scratch, manipulated and then saved in one file with some other info.
But again, for this I needed an example.

Timo

Re: Multiple images in one file

Posted: Sun Apr 18, 2010 5:39 pm
by ts-soft

Re: Multiple images in one file

Posted: Mon Apr 19, 2010 9:11 am
by omit59
Thanks ts-soft, but I'm not sure that is suitable for this job?

I was thinking something like Gimp-layers, so that layers can be added during program running, and edited seperately.
Includefile or resources don't suit for that, or do I understand right? (never used resources though)

Timo

Re: Multiple images in one file

Posted: Mon Apr 19, 2010 1:08 pm
by ts-soft
you can create a bin-file and use in nearly the same way as packfile, with better
comfort and more packformats.

Re: Multiple images in one file

Posted: Mon Apr 19, 2010 3:08 pm
by srod
ts-soft's PureDataComverter tool is great; it works a treat.

I have nearly finished my wrapper around OLE's compound file implementation which also gives a very simple way of saving multiple files to a single document etc. :) You can create the individual files within the document and then write to them using commands very similar to PB's file commands. Pull out individual files just like you can from your hard drive etc... This will let you create a single document for your applications containing images, text, spreadsheets, PB source files... anything, and without having to worry about the 'directory/file structure' etc.

The only downside thus far... multiple simultaneous access to individual document files is not possible through COM's standard implementation of one of the interfaces involved! Still, it could have its uses nevertheless.

Re: Multiple images in one file

Posted: Mon Apr 19, 2010 3:12 pm
by Kaeru Gaman
on the other hand, something like layered images is an individual file structure,
means you have a header for the structure and a bunch of images following.

when you write a program handling layered images, you'll need a LList or an Array to handle the layers, anyways.
then you can put the LList and the Images into a compressed arcive and write it to disk in one access and load it to the memory in one access.

a layered image file normally would completely be in memory, loaded as whole and saved as whole, not the single layers saved individually.

Re: Multiple images in one file

Posted: Wed Apr 21, 2010 8:24 pm
by srod
@omit59 : I can now point your towards my aforementioned Window's OLE compound file implementation ... http://www.purebasic.fr/english/viewtop ... 12&t=41980

It will certainly allow you to save multiple images within a single file and in such a way that you can easily retrieve individual images etc. (One of the demos does exactly this!) It might help.

Re: Multiple images in one file

Posted: Thu Apr 22, 2010 7:05 am
by omit59
Thanks to all for your replies

I'll check them them now and decide what is best for this job.

Timo