Multiple images in one file

Just starting out? Need help? Post your questions and find answers here.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Multiple images in one file

Post by omit59 »

Anybody having an example how to save and load multiple images in same file?

Timo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Multiple images in one file

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Multiple images in one file

Post by Kaeru Gaman »

also consider using Windows Ressources, to put all Images you need into your EXE.
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Multiple images in one file

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Multiple images in one file

Post by Kaeru Gaman »

sure.
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.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Re: Multiple images in one file

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Multiple images in one file

Post by ts-soft »

omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Re: Multiple images in one file

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Multiple images in one file

Post by ts-soft »

you can create a bin-file and use in nearly the same way as packfile, with better
comfort and more packformats.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Multiple images in one file

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Multiple images in one file

Post 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.
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Multiple images in one file

Post 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.
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Re: Multiple images in one file

Post by omit59 »

Thanks to all for your replies

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

Timo
Post Reply