Thanks so much!
Here is an example of the code...
' saves the contents of a picturebox to a file
' supports GIF/JPG/TIF/PNG and various others
Public Function PictureBoxToFile(ByVal pic As PictureBox, ByRef
sFilename As String, Optional lQuality As Long = 85) As Long
Dim sExtension As String
Dim bitmap As Long
Dim lError As Long
Dim params As EncoderParameters
Dim lQual As Long
Dim lIndex As Long
Dim tguid As GDIPlus.Guid
sExtension = GetExtension(sFilename)
lIndex = ExtensionExists("*." & sExtension)
If lIndex > -1 Then
lError = GdipCreateBitmapFromHBITMAP(pic.Picture.Handle,
pic.Picture.hPal, bitmap)
If Not lError Then
If (Asc(sExtension) And Not 32) = vbKeyJ Then ' lazy
JPEG/JPG/JPE/JFIF checking :P
lQual = lQuality
params.Count = 1
params.Parameter.Guid = StringToGuid(EncoderQuality)
params.Parameter.NumberOfValues = 1
params.Parameter.Type = EncoderParameterValueTypeLong
params.Parameter.Value = VarPtr(lQual)
lError = GdipSaveImageToFile(bitmap, sFilename,
tGuids(lIndex), params)
Else
lError = GdipSaveImageToFile(bitmap, sFilename,
tGuids(lIndex), ByVal 0)
End If
If Not lError Then
GdipDisposeImage bitmap
PictureBoxToFile = True ' tada!
Else
RaiseEvent Error(lError, GdiErrorString(lError))
End If
Else
RaiseEvent Error(lError, GdiErrorString(lError))
End If
End If
End Function
See if these pages are of any use to you, there may be more if you hunt
around on Google:
http://www.dotnet247.com/247reference/msgs/29/147843.aspx
http://csharpfriends.com/Forums/ShowPost.aspx?PostID=6329#6329
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: ED...@mvps.org
WWW: Http://www.mvps.org/EDais/