|
-
Apr 28th, 2001, 04:21 PM
#1
Thread Starter
Junior Member
Save PictureBox contents to a file?
Help!
Here's what I'm trying to achieve...
Firstly, my project is just a database of names along with pictures of that person.
At present, I have an Access Database (created in Access 2k). The "photograph" field is set as "OLE Object".
My VB project can interface with the DB with the code below and successfuly ADD records easily. The only thing it won't do is add the record (including the picture) if I try to set RS("Photograph") = Picture1.Picture.
Code:
Dim DB as Database
Dim RS as Recordset
Set DB = OpenDatabase("C:\Control.mdb")
Set RS = DB.OpenRecordset("Staff",dbOpenDynaset)
RS.AddNew
RS("Name") = Me.txtForename & " " & Me.txtSurname
RS("Photograph") = Picture1.Picture 'it all works if I take this out
RS.Update
I want to store the contents of the Picture1 picturebox as a File in a directory, and input the file path and name into the database rather than the file itself. I don't know how to ouput the picturebox to a file.
Since the Picture1 box gets its picture from a TWAIN source (I got this bit to work), the picture doesn't actually exist as a file anywhere yet. So I need to 'dump' the contents of the Picturebox into a file in a folder somewhere. If you can help with this, please do!
And once I know how to do that, is it easy to then load the contents of a file into the picturebox again?
Many thanks for your help.
Regards,
Richard.
-
Apr 28th, 2001, 04:36 PM
#2
Use SavePicture and LoadPicture().
Code:
'Save
SavePicture Picture1.Picture, "C:\MyPic.bmp"
'Load
Picture1.Picture = LoadPicture("C:\MyPic.bmp")
-
Apr 28th, 2001, 05:26 PM
#3
Thread Starter
Junior Member
JPEGS?
What about using SavePicture() and LoadPicture() to save and display JPEGS?
-
Apr 28th, 2001, 06:00 PM
#4
Does this work?
Dim DB as Database
Dim RS as Recordset
Set DB = OpenDatabase("C:\Control.mdb")
Set RS = DB.OpenRecordset("Staff",dbOpenDynaset)
RS.AddNew
RS("Name") = Me.txtForename & " " & Me.txtSurname
savepicture Picture1.Picture, "X:\your path\your picture.jpg"
RS("Photograph") = "X:\you path\your picture.jpg"
RS.Update
-
Apr 28th, 2001, 06:28 PM
#5
You can use the LoadPicture to load images of the following types:
BMP, JPG, GIF, WMF, ICO and CUR.
When you use SavePicture the picture is saved using the original image type. That is if you load a GIF and make a call to SavePicture the image will be saved in GIF format.
If you use SavePicture on a PictureBox.Image property the picture is always saved as a BMP file.
-
Apr 28th, 2001, 06:32 PM
#6
There are some exceptions, however, such as if you load a picture in BMP format, then convert it to an ICO (through VB) then it will save as an icon.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|