![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. My code is 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) '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 Sub Form1_Close FileClose(c1) End Sub Any ideas? Thanks - Bats |
|
|||
|
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. -dlfallen |
|
|||
|
Hey guys
Thanks for the tips, I'll try check them out. 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. Bats |
|
|||
|
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 Sub Form1_Close FileClose(c1) 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.
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD. Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD. "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. -dlfallen |
|
|||
|
Thanks for the Do While tip works great, note I had to check for the file length less 40
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) Do While bin.Position < bin.Length-40 msgbox("position = " & bin.Position & " length = " & bin.Length) ImageList1.Add(bin.RetrieveImage) Loop Image1.Image = imagelist1.Item(0) End Sub |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with Binaryfile | Pim93 | Questions & Help Needed | 3 | 02-20-2008 06:10 PM |
| Selecting multiple files using OpenDialog | burd27 | Questions & Help Needed | 1 | 02-07-2008 06:06 PM |
| selecting multiple lines as remark | Stellaferox | Basic4ppc Wishlist | 3 | 05-26-2007 11:50 AM |
| Move an image inside an image control | Cableguy | Questions & Help Needed | 5 | 05-14-2007 08:40 PM |
| BinaryFile Error | dlfallen | Bug Reports | 2 | 05-01-2007 09:34 PM |