PDA

View Full Version : saving Images



Ice
10-04-2009, 07:50 PM
Hi!
I would like to know if there is a(n)(easy)way to save images(of different extensions) to a file and to load them back from the file ..(without using rar or other archive file types)

Wizard
10-04-2009, 08:49 PM
I think you need some sort of editor to do that, i.e. unDelphix allows you to save all images in dxImageList to one *.dxg file. You can then load, add and remove images from the dxg file. Don't know how to program such an editor though ::)

chronozphere
10-04-2009, 09:30 PM
Hmm.. Undelphix is only a good choice when you are allready using it in your game/application.

You could try this one:

http://www.delphizip.org/

Or this one:

http://www.dellapasqua.com/delphizlib/ (http://www.dellapasqua.com/delphizlib/)

Or check a few of these:

http://www.torry.net/pages.php?s=99

Hope this helps. :)

Ice
10-04-2009, 09:54 PM
Well so much for easy solutions..but thnx for the help I will try them soon..
Still is there no other way ? :)

chronozphere
10-04-2009, 10:19 PM
You could use google to find even more zib/compression libraries, or you could write your own package system. If you don't have a lot of demands, this can be simple. If you want to have directories within the package, it becomes a lot harder (I can tell, I've been there. ;) ).

You could write your own package loader/saver by using streams. This may be a good choice as you will learn alot. Check this link If you want to get crackin with Streams:

http://delphi.about.com/od/vclusing/l/aa110803a.htm (http://delphi.about.com/od/vclusing/l/aa110803a.htm)

You just make a TFileStream object to create a new file (or open an existing one). After that, you can feed your data to the stream, or read data from it. Usually, you start with a little header telling you what and how many data is stored in the file. By using the header data, you can read chunks of data and treat them as seperate files. You could then load the files into your application. (Remember that many objects like TBitmap have a LoadFromStream and SaveToStream method).

Just take a look at streams if you find it interesting. If you want a simple example of how to use them, just ask. ;)

Ice
10-04-2009, 10:37 PM
This is much better thnx ! ;D
A few exaples would be nice .. :)

ize
11-04-2009, 01:39 PM
Have a browse through this excellent site. Chances are, your question has been asked before (most of mine have been :)) Maybe not exactly what you're looking for, but here's what i dug up:

Link (http://www.pascalgamedevelopment.com/forum/index.php?topic=5694)
Link (http://www.pascalgamedevelopment.com/forum/index.php?topic=1460)
Link (http://www.pascalgamedevelopment.com/forum/index.php?topic=4275)

Ice
26-04-2009, 01:40 PM
Hi!
I am having a little trouble (as always:( ) with loading a picture from a file to a tpicture variable..
Here's what I have problem's with:


type
tpack=record
kep:tpicture;
nr:integer;
hsize:int64;
fsize:int64;
end;
var
lpack:array [1..9999] of tpack;
...
lpack[1].nr:=1;
lpack[1].kep.LoadFromFile('D:\integralas1.jpg');
//It won't let me load the picture.. it gives an error saying "raised exception Class
//EAccessViolation with message 'Access violation at adress 00404107 in module .. read
//of adress 00000000'" I think it's because I have to "initialize" the tpicture
//component somehow but I don't know how ..
lpack[1].hsize:=sizeof (lpack[1]);
lpack[1].fsize:=sizeof (lpack[1]);
...

Can you please help ?

VilleK
26-04-2009, 02:12 PM
Initialize:

lpack[1].kep := TPicture.Create;

Then later when you want to clean up and free memory;

lpack[1].kep.Free;

Ice
26-04-2009, 02:31 PM
thnx a lot !
Btw will this write the picture to the file ?(in case of large pictures as well.. )

strm.Writebuffer(lpack[1],sizeof (tpack));

chronozphere
26-04-2009, 04:22 PM
I think we need to see more of your source. What does TPack look like?

tpascal
27-04-2009, 05:35 PM
Btw will this write the picture to the file ?(in case of large pictures as well.. )


It dosent works like that, you cant save to disk any class variable passing just the pointer and using sizeof(); it will save just garbage; it is not a continues block of memory, there are pointers everywhere.

So, you wish to load severals images with loadfromfile() and then save all of then in your own custom resource file?, then these are my advices:

Mainly there are two techniques you can use, one is packing in one file several files in his native format, example, you have severals JPgs file ( pic01.jpg, pic02.jpg, pic03.jpg etc), you open and read each one using file read procedures (binary files, file stream etc), and write all bytes to your pack file in consecutive blocks. You need to prepare your pack file writing first a header wich tells how much files are empacked and the size in bytes of each one so you can later extract every file.

Later when you need the image you extract the block bytes from the resource (to a temp file for example) and use procedures like loadfrom() for get the images in memory. That is why some people already advice you to check a ZIP or ZLIb library which does just that, empack several files in just one resource and then allow you to extract desired files, some libs even allow you to use procedures like loadfromfile() to open teh file directly from resource with not need to use temp files.

The other technique is similar, pack in one resource several images but you just save the pixels, that way is easier to read back in memory the images with not need to use temp files. You open each image with procedures like loadfromfile() then you use class methods to access the image pixels and save the data in your resource file; yet you need to save the info about image dimensions so you can build back the image.

In this method i recomend to uniform the image to same picture format for all images in your resource, for example uncompressed 32 bit color; use tbitmap class to convert whatever format you open with tpicture using the draw method, and access the pixels using scanline method.

good luck.

Ice
07-05-2009, 06:39 PM
Sorry for the late reply but I was bussy with school .. you really helped me out!
Thnx for all the help !