Results 1 to 11 of 11

Thread: Saving image from an OLE control to a bitmap file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    8
    What is the best way of saving an (bitmap) image in an OLE control to a bitmap (.bmp) file. This is the method I'm using but I get a "No object" error at the line,
    "olePicture.SaveToFile (FileNumber)".


    Dim FileNumber As Integer
    Dim LocationAndFileName As String
    FileNumber = FreeFile()
    LocationAndFileName = App.Path & "\Logo.bmp"

    Open LocationAndFileName For Binary As #FileNumber

    olePicture.SaveToFile (FileNumber)

    Close #FileNumber

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Use

    Image1.picture = loadpicture("whatever")
    SavePicture Image1.picture, "C:\Test.bmp"

    Good luck

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    8
    I thought about using the image control with SavePicture but the picture is actually loaded into the OLE control from an access database field that is itself an OLE field. I then want to dump the picture from the OLE control to a bitmap file.

    One option might be to load an image control with the picture from the OLE control. (I've already tried loading the picture into an image or picture control directly from the OLE field in the database but this didn't work). Then using the SavePicture routine to save the image to a bitmap from that image control. I don't know how set an image/picture control to display the image in the OLE control though. Any ideas?

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    I have never used the OLE control. I have made a test database in access with image file.

    How did you bind the field to the OLE control?

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    8
    I just used a simple data control.

    I got that code working that I previously posted but found that the file content saved was not actually a bitmap. So after the routine saved the file from the OLE control the file was not editable in Paint. What a bummer. I think I'm barking up the wrong tree here.

    How did you store an image into an MS Access field and retreive it to a image/picturebox control in VB?

  6. #6
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Never mind, I found out. I have to connect using an DAO control rather than an ADO control.

    Now I will try to transfer the picture to the Image box.
    Chemically Formulated As:
    Dr. Nitro

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    8
    What data type did you use for the field in the MS Access database to store the image? (Eg: Text, Number, OLE etc.)

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Binary Ole

    I am still working on this!

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I got something working, but it doesn't really look nice. The olecontrol must be running, in order to access the picture. This pops up a menubar, which shifts the form a bit down. I used an invisible picturebox to copy the picture to, and then used the savepicture method.
    Code:
    Private Sub Command1_Click()
        OLE1.DoVerb
        Picture1.AutoRedraw = True
        Picture1.PaintPicture OLE1.Picture, 0, 0, Picture1.Width, Picture1.Height, 0, 0, ScaleX(OLE1.Picture.Width, vbHimetric, vbTwips), ScaleY(OLE1.Picture.Height, vbHimetric, vbTwips)
        Set Picture1.Picture = Picture1.Image
        SavePicture Picture1.Picture, "c:\temp\test1234.bmp"
        OLE1.Close
    End Sub
    
    Private Sub OLE1_Resize(HeightNew As Single, WidthNew As Single)
        Picture1.BorderStyle = 0
        Picture1.Height = HeightNew
        Picture1.Width = WidthNew
    End Sub

  10. #10
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Try this one Pactor1!

    I used Fransc's code but add on additional part.


    Private Sub Command1_Click()
    'PURPOSE:Resize the controls
    OLE1.SizeMode = 2
    DoEvents
    Picture1.Width = OLE1.Width
    Picture1.Height = OLE1.Height

    OLE1.DoVerb
    Picture1.AutoRedraw = True
    Picture1.PaintPicture OLE1.Picture, 0, 0, Picture1.Width, Picture1.Height, 0, 0, ScaleX(OLE1.Picture.Width, vbHimetric, vbTwips), ScaleY(OLE1.Picture.Height, vbHimetric, vbTwips)
    Set Picture1.Picture = Picture1.Image
    SavePicture Picture1.Picture, "c:\Temp\Test.bmp"
    OLE1.Close
    End Sub
    Private Sub OLE1_Resize(HeightNew As Single, WidthNew As Single)
    Picture1.BorderStyle = 0
    Picture1.Height = HeightNew
    Picture1.Width = WidthNew
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    8
    Thanks, guys. I've implemented the code and it's working well.

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