Hi all
I hope this one is not too obvious, but I cannot see how to select the image to retrieve from a BinaryFile. My code just gets each image in sequence but I want to be able to go forwards and backwards and get images based on the position in the file.
Form1.Show
FileOpen(c1,"data.dat",cRandom)
bin.New1(c1,true)
'this get the first image in the sequence
Image1.Image = bin.RetrieveImage
End Sub
Sub Num1_ValueChanged
'and then this gets the next but how do I get a specific image
'or get a previous image?
Image1.Image = bin.RetrieveImage
End Sub
I'm not all that clued up on this myself but I think you need to add all the images it an imagelist control and then you will be able to select which ever one you want.
Regards,
RandomCoder.
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
I've wrestled with this quite a bit. See the Image Explorer post under "Share Your Creations" on this forum. There is a program (with source code) that will scroll back and forth among BMP files stored in a binary file. I have updated this program to handle all supported graphic file types, and will post the final version on the Forum sometime this weekend.
Basically, you have two choices. One, as mentioned by RandomCoder, is to read all the images into an ImageList control. The other is to access an arbitrary image file by specifying its starting location before issuing the RetrieveImage command. The Image Explorer program mentioned above is a tool that can give you that information.
I did think of another "brute force" method using the RetrieveFile command to export the required image out as say "CurrentImage.jpg" and then reimporting it back into the required location.
Tried out the ImageList control and its great, just need to work out a way of determining how many images are in the file
Sub App_Start
'FileOpen(c1,"data.dat",cRandom)
'bin.New1(c1,true)
'bin.EmbedFile (AppPath & "\build.jpg")
'bin.EmbedFile (AppPath & "\wall.jpg")
'bin.EmbedFile (AppPath & "\garden.jpg")
'FileClose(c1)
Form1.Show
FileOpen(c1,"data.dat",cRandom)
bin.New1(c1,true)
for x = 0 to 2
ImageList1.Add(bin.RetrieveImage)
next x
Image1.Image = imagelist1.Item(0)
End Sub
Sub Num1_ValueChanged
Image1.Image = imagelist1.Item(num1.Value)
End Sub
Instead of the For Next loop you could try a Do Until.
Once again I've not done this myself (I've not had any need yet), but I'd expect you to either receive an EOF or Error which could be used as the signal to drop out of the loop.
Regards,
RandomCoder.
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Actually, what usually happens when you try to retrieve a file past the end of the binary file is the program crashes. What I do in my Image Explorer program is check the file positon after each image retrieval. It the image position + 32 is greater than the file size
FileSize(OpenDialog1.File)
then I know I have read the last image in the file.
I have posted the final version of Image Explorer in the Share Your Creations section. The source code there illustrates the method.