Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complex Image Question 1

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Hi,
I want to store images, (as text or whatever) in one file, then retrieve the images 4 use.

I thought of opening the images 4 input, writing them to lines on an Ini, and then reading them but that isn't reliable.

Any ideas.
Brad,
Free mp3 player,games and more.
 
Why don't you store the images as separate files into a folder?

Anyway, storing images as text files doesn't seem a good idea to me: You run the risk that VB will mis-interpret some of the characters: You should certainly store them as Binary files. _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
The reason for only using one file is so they can be destribute the skins easily and more safely.

How do I store them as binary then? Brad,
Free mp3 player,games and more.
 
Can you use a resource (.res) file? or am I misinterpreting your question?
Dragnut
 
Okay heres the full blue print, I have my mp3 playerr.
Its has 5 buttons
Each Button Has An image up and image down
Form has an image
There is an include program to put all these files into
one file, So the user can create his own skins adn distrubte them at there will.

Thanks,
Brad,
Free mp3 player,games and more.
 
Sure. Assuming that your pictures are actually held as StdPicture objects (e.g they are held in a PictureBox, an Image, or you have loaded them through LoadPicture) you can use a fairly neat trick involving PropertyBags. The following example (and I leave you to extend it to your use) requires that you have a form with 4 picture boxes. Picture1 and Picture2 should contain the images that you want to save and later reload. Picture3 and Picture4 should be left blank. You also want two Command buttons. Command1 saves the two images in a single file, and Command2 will retrieve them into the two blank picture boxes:

Option Explicit

Private Sub Command1_Click()
Dim pb As PropertyBag
Dim vartemp As Variant
Dim hFile As Long

Set pb = New PropertyBag

hFile = FreeFile
Open "C:\multipics.mpc" For Binary As hFile


pb.WriteProperty "FormSkin", Picture1
pb.WriteProperty "Button1PictureDown", Picture2

vartemp = pb.Contents
Put hFile, , vartemp
Close hFile

End Sub

Private Sub Command2_Click()
Dim pb As PropertyBag
Dim vartemp As Variant
Dim bytearr() As Byte
Dim hFile As Long

hFile = FreeFile
Open "C:\multipics.mpc" For Binary As hFile

Get hFile, , vartemp
bytearr = vartemp

Set pb = New PropertyBag
pb.Contents = bytearr

Set Picture3 = pb.ReadProperty("FormSkin")
Set Picture4 = pb.ReadProperty("Button1PictureDown")

Close hFile
End Sub
 
Thanks this looks like this will work, but could u give me some more info on how to create these mpc's so I can tailor it better to my application.


This is really what I need,


Brad,
Free mp3 player,games and more.
 
All the necessary information is in the example. I stupidly thought that you'd understand how it worked, particularly if you are capable of writing an mp3 player. A foolish assumption on my behalf. OK, here's an explanation.

1) The example provided, whilst used in this particular case to save and reload pictures, is actually a routine that allows you to save and reload any single or multiple ActiveX object(s). Therefore the name of the file used to store the items is basically irrelevant. I happened to have called it "multipics.mpc" in the example because I was tailoring it to your stated requirements. It could just have easily called "ElvisHasLeftTheBuild.ing"

2) Saving. The technique makes use of the PropertyBag object. The official use of these is for persisting objects between seperate invocations of those objects - but we cheat. We save one or more properties to the PropertyBag. In the examples case those properties just 'happen' to be picture objects. Now - and this is where we cheat a bit - having got them into the propertybag as seperate, named properties (e.g FormSkin, Button1Up, Button1Down, Button2Up, Button2Down, etc. would work as names for you, hence the names I used in the actual example), we can now extract the entire contents of the bag into a single variant. We can then use normal binary file handling techniques to save that variant to a file (whatever it's name might be).

3) Loading. Now we just need to reverse the saving process. There's one tiny caveat, which is that we can only set the contents of a propertybag from a byte array. So we use normal file handling techniques to open the file we earlier saved, and read the variant (which is really just a binary representation of all the objects). This is then converted into a byte array, and is used to load the contents of an empty propertybag. We can then retrieve the previously stored objects by the same names we saved them to the propertybag in phase 2.
 
Hey, listen: if you don't want o give any stars out, do you think that your mp3 player's About screen will credit tek-tips...
 
1:About the stars, I give them out when I get the code to work.

2 Now that I read ur code deeply I realizr that is frickin simple. So thanks anyhoo 4 explain it. Brad,
Free mp3 player,games and more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top