-
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
-
Use
Image1.picture = loadpicture("whatever")
SavePicture Image1.picture, "C:\Test.bmp"
Good luck
-
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?
-
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?
-
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?
-
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.
-
What data type did you use for the field in the MS Access database to store the image? (Eg: Text, Number, OLE etc.)
-
Binary Ole
I am still working on this!
-
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
-
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
-
Thanks, guys. I've implemented the code and it's working well.