Results 1 to 6 of 6

Thread: Save PictureBox contents to a file?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Northern Irelans
    Posts
    17

    Arrow 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.

  2. #2
    Matthew Gates
    Guest
    Use SavePicture and LoadPicture().


    Code:
    'Save
    
    SavePicture Picture1.Picture, "C:\MyPic.bmp"
    
    
    'Load
    
    Picture1.Picture = LoadPicture("C:\MyPic.bmp")

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Northern Irelans
    Posts
    17

    JPEGS?

    What about using SavePicture() and LoadPicture() to save and display JPEGS?

  4. #4
    coolboris
    Guest

    Question 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

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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.

  6. #6
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width