Multiple images in one file
Multiple images in one file
Anybody having an example how to save and load multiple images in same file?
Timo
Timo
Re: Multiple images in one file
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.
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.
I may look like a mule, but I'm not a complete ass.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Multiple images in one file
also consider using Windows Ressources, to put all Images you need into your EXE.
oh... and have a nice day.
Re: Multiple images in one file
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.
I may look like a mule, but I'm not a complete ass.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Multiple images in one file
sure.
I just wanted to mention this additional option if he wanted to create an archive to come with his exe.
I just wanted to mention this additional option if he wanted to create an archive to come with his exe.
oh... and have a nice day.
Re: Multiple images in one file
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
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
you can use this tool: http://www.purebasic.fr/english/viewtop ... 63#p262763
Re: Multiple images in one file
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
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
you can create a bin-file and use in nearly the same way as packfile, with better
comfort and more packformats.
comfort and more packformats.
Re: Multiple images in one file
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.
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.

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.
I may look like a mule, but I'm not a complete ass.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Multiple images in one file
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.
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.
oh... and have a nice day.
Re: Multiple images in one file
@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.
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.
I may look like a mule, but I'm not a complete ass.
Re: Multiple images in one file
Thanks to all for your replies
I'll check them them now and decide what is best for this job.
Timo
I'll check them them now and decide what is best for this job.
Timo