I'm trying to create "encrypted" images for a program by:
1. Loading the image,
2. Making a Memblock from it,
3. Then writing the Memblock to a file.
Then, to open the "encrypted" image, I'm:
1. Loading the file,
2. Making a Memblock from it,
3. Then making an image from the Memblock.
When I load the new file, and make a Memblock from it, it has an extra byte of data at the beginning! I can copy the Memblock to a new one by skipping the first byte but that seems like a workaround for something I may not be understanding and doing correctly.
Does the extra byte of information have a purpose, is it a bug, or is it something that I am doing incorrectly?
Here is some code for an example of my situation:
sync on
sync rate 60
set display mode 640, 480, 32
dirPath$ = "c:\DBP\"
`Load an image and create a memblock(1) out of it.
load image dirPath$ + "linkyr.jpg", 1, 1
make memblock from image 1, 1
`Delete the image, then make a new image(1) from the new memblock(1).
delete image 1
make image from memblock 1, 1
`Create a new file to write the memblock(1) to.
if file exist(dirPath$ + "link.file") then delete file dirPath$ + "link.file"
open to write 1, dirPath$ + "link.file"
write memblock 1, 1
close file 1
`Reopen the file and create a new memblock(2) with it.
open to read 1, dirPath$ + "link.file"
make memblock from file 2, 1
make image from memblock 2, 2
close file 1
`Create a new memblock(3) that's one byte smaller than memblock(2).
`Then skip the first byte.
make memblock 3, GET MEMBLOCK SIZE(2) - 4
copy memblock 2, 3, 4, 0, GET MEMBLOCK SIZE(2) - 4
`Create an image(3) from the new (3) memblock
make image from memblock 3, 3
`Main Loop
do
`Draw images and titles
set cursor 0,0
print "Image from Memblock(1)"
set cursor 200,0
print "Image from Memblock(2)"
set cursor 400,0
print "Image from Memblock(3)"
paste image 1, 0, 16
paste image 2, 200, 16
paste image 3, 400, 16
`Memblock descriptions
set cursor 0,166
print "Memblock(1) is created from loaded image."
print "Memblock(2) is created from file created by Memblock(1)."
print "Memblock(3) is created from copied Memblock(2) minus the first byte."
print
`First 3 bytes from Memblocks
print "First 3 bytes from Memblock(1): " + str$(MEMBLOCK BYTE(1, 0)) + ", " + str$(MEMBLOCK BYTE(1, 4)) + ", " + str$(MEMBLOCK BYTE(1, 8))
print "First 3 bytes from Memblock(2): " + str$(MEMBLOCK BYTE(2, 0)) + ", " + str$(MEMBLOCK BYTE(2, 4)) + ", " + str$(MEMBLOCK BYTE(2, 8))
print "First 3 bytes from Memblock(3): " + str$(MEMBLOCK BYTE(3, 0)) + ", " + str$(MEMBLOCK BYTE(3, 4)) + ", " + str$(MEMBLOCK BYTE(3, 8))
print
`Memblock sizes
print "Memblock(1) Size: " + str$(GET MEMBLOCK SIZE(1))
print "Memblock(2) Size: " + str$(GET MEMBLOCK SIZE(2))
print "Memblock(3) Size: " + str$(GET MEMBLOCK SIZE(3))
sync
loop
`Clean Up
delete image 1
delete image 2
delete image 3
delete memblock 1
delete memblock 2
delete memblock 3
Here is the image I'm using for the example:
And here is an image of the above code running:
Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.