Anticipation
Member
- Joined
- Jul 15, 2008
- Messages
- 10
- Programming Experience
- Beginner
I'm trying to save an image drawn onto a PictureBox, using the sub procedure
And then calling it using
The problem is, that on saving i just get a blank png. Any help would be appreciated. Thanks.
VB.NET:
Sub SaveImage(ByVal pb As PictureBox, ByVal sFile As String)
Dim bmp As New Bitmap(pb.Width, pb.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim pe As New PaintEventArgs(g, New Rectangle(Point.Empty, bmp.Size))
Me.InvokePaint(pb, pe)
Dim fmt As Imaging.ImageFormat
Dim lFile As String = sFile.ToLower
If lFile.EndsWith(".emf") Then
fmt = Imaging.ImageFormat.Emf
ElseIf lFile.EndsWith(".exif") Then
fmt = Imaging.ImageFormat.Exif
ElseIf lFile.EndsWith(".gif") Then
fmt = Imaging.ImageFormat.Gif
ElseIf lFile.EndsWith(".jpg") OrElse lFile.EndsWith(".jpeg") Then
fmt = Imaging.ImageFormat.Jpeg
ElseIf lFile.EndsWith(".png") Then
fmt = Imaging.ImageFormat.Png
ElseIf lFile.EndsWith(".tiff") OrElse lFile.EndsWith(".tif") Then
fmt = Imaging.ImageFormat.Tiff
ElseIf lFile.EndsWith(".wmf") Then
fmt = Imaging.ImageFormat.Wmf
Else
fmt = Imaging.ImageFormat.Bmp
End If
bmp.Save(sFile, fmt)
g.Dispose()
bmp.Dispose()
pe.Dispose()
End Sub
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveImage(picCanvas, "c:\test.png")
End Sub