DarkBasic Pro
Hi all
Some days ago I was trying to find an easy way to pack files (in this case image files) in a single file, and found a very little information and no examples in the help file of DBPro.
Maximilian told me that with the Enhancements Expansion Pack we can make it easy and fast, and it's real (Yesterday I bought it and I'm waiting to download). But I want to pack only image files, and the IMAGEBLOCK command is enough for me and is included in the image DBPro commands.
Also, I don't want to encrypt the data at this moment. All I want is to hide the images to the mid-level-user eyes and the IMAGEBLOCK command works nice if we use a patch. Thanks to Pixel Paint for his patch contribution!
If it's useful to someone it will be nice.
Ok, there we go.
The example is divided in two projects. The first shows how to create the packed file and the second how to load and use this file. I added the three image files of the example, and the projects are in the post in a rar file to download, but you can use whatever image files you like if you rename to use with this source code whit image_1.jpg, image_2.jpg and image_3.jpg (if the files you use are .jpg files!)
The project files are auto-commented. So, here is the source of the project 1, to create the packed file.
Rem ***** IMAGEBLOCK SAMPLE 1: CREATING THE PACKED FILE *****
// 1- Open/create the file to store the images
// (I use *.idt from ImageDaTa but you can use any other name)
// 2- Set the name of the file and the second argument to 0 (write mode)
// 3- INSERT THIS LINE to patch the IMAGEBLOCK command. (Thanks, Pixel Paint)
// 4- Load the images into memory
// (IMAGEBLOCK auto-creates the packed file)
// 5- And close the image block.
OPEN IMAGEBLOCK "My_file.idt", 0 //(1)-(2)
exclude from imageblock "false_data" // (3)
LOAD IMAGE "image_1.jpg", 1 // (4)
LOAD IMAGE "image_2.jpg", 2
LOAD IMAGE "image_3.jpg", 3
CLOSE IMAGEBLOCK // (5)
do
set cursor 0,0
print "My_file.idt created/updated. Press esc to exit."
wait key
loop
end
And here the source of project 2. REMEMBER to copy the created file My_file.idt whit project 1 in the proyect 2 folder!
Rem ***** IMAGEBLOCK SAMPLE 2: LOADING IMAGES *****
sync on: sync rate 60: autocam on
backdrop off : set ambient light 50 : maximize window
make object box 1, 40, 48, 4
// 1- Open the file created in the first example.
// 2- Set the second argument to 1 (read mode)
// 3- Load the images into memory
// 4- And close the image block.
OPEN IMAGEBLOCK "My_file.idt", 1 //(1)-(2)
LOAD IMAGE "image_1.jpg", 1 // (3)
LOAD IMAGE "image_2.jpg", 2
LOAD IMAGE "image_3.jpg", 3
CLOSE IMAGEBLOCK // (4)
// Show the images loaded form My_file.idt
do
set cursor 0,0
print "Press esc to exit."
if spacekey()=1 then exit
texture object 1, 1
scale object texture 1, 1, 1
sync
sleep 600
texture object 1, 2
scale object texture 1, 1, 1
sync
sleep 600
texture object 1, 3
scale object texture 1, 1, 1
sync
sleep 600
loop
// That's all
end
See you.
JavierTF