Hi,
To save the picture property of a picturebox you can simply use the SavePicture statement. To save an image created in a picturebox is more complex, I managed to addapt some code found in the MSDN article Q161299 to do the job. You can find this at:
http://support.microsoft.com/support...S&SD=msdn&FR=0
There may be an easier way to do this but I couldn't find it so for what it's worth here is the code I use (without any error handling,so you may wish to look at that).
To test this create a project with a default form containing a picturebox Picture1 with SCALEMODE set to PIXELS and a command button command1. Paste this code, create some graphics at design time and hit the command1 hopefully a bitmap "test.bmp" will be created in the "C:Temp" directory.
Option Explicit
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" ( _
ByVal hdc As Long, ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" ( _
ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" ( _
ByVal hDCDest As Long, ByVal XDest As Long, _
ByVal YDest As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hDCSrc As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) _
As Long
Private Declare Function DeleteDC Lib "gdi32" ( _
ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetWindowDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Type picBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Declare Function OleCreatePictureIndirect _
Lib "olepro32.dll" (PicDesc As picBmp, RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function StretchBlt Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal nSrcWidth As Long, _
ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Function CreateBitmapPicture(ByVal hBmp As Long) As Picture
Dim R As Long
Dim Pic As picBmp
' IPicture requires a reference to "Standard OLE Types."
Dim IPic As IPicture
Dim IID_IDispatch As GUID
' Fill in with IDispatch Interface ID.
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
' Fill Pic with necessary parts.
With Pic
.Size = Len(Pic) ' Length of structure.
.Type = vbPicTypeBitmap ' Type of Picture (bitmap).
.hBmp = hBmp ' Handle to bitmap.
End With
' Create Picture object.
R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
' Return the new Picture object.
Set CreateBitmapPicture = IPic
End Function
Public Function exportBmp(PBox As PictureBox) As Picture
'
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim R As Long
Dim hDCSrc As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim RasterCapsScrn As Long
Dim HasPaletteScrn As Long
Dim PaletteSizeScrn As Long
Dim WidthPix As Single
Dim HeightPix As Single
WidthPix = PBox.ScaleWidth
HeightPix = PBox.ScaleHeight
hDCSrc = GetWindowDC(PBox.hwnd) ' Get device context for pbox.
' Create a memory device context for the copy process.
hDCMemory = CreateCompatibleDC(hDCSrc)
' Create a bitmap and place it in the memory DC.
hBmp = CreateCompatibleBitmap(hDCSrc, WidthPix, HeightPix)
hBmpPrev = SelectObject(hDCMemory, hBmp)
' Copy the on-screen image into the memory DC.
R = BitBlt(hDCMemory, 0, 0, WidthPix, HeightPix, hDCSrc, _
0, 0, vbSrcCopy)
' Remove the new copy of the on-screen image.
hBmp = SelectObject(hDCMemory, hBmpPrev)
' Release the device context resources back to the system.
R = DeleteDC(hDCMemory)
R = ReleaseDC(PBox.hwnd, hDCSrc)
' Call CreateBitmapPicture to create a picture object from the
' bitmap. Then return the resulting picture object.
Set exportBmp = CreateBitmapPicture(hBmp)
End Function
Private Sub Command1_Click()
'
'save as bitmap option prompts for file name
Dim FileSpec As String
FileSpec = "c: empTest.bmp"
SavePicture exportBmp(Picture1), FileSpec
End Sub
Good Luck Phil