EDN Admin
Well-known member
I have this Function GetFormImage that I have used in the past but in this project I get the Error New cannot be used on an interface. Code below, any help is greatly appreciated.
All the New are throwing the Error. Private Sub Save_Image()
Try
Dim img As Image = GetFormImage(True)
img.Save("image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
Me.Text = ex.Message
End Try
End Sub
Private Function GetFormImage(ByVal include_borders As Boolean) As Bitmap
Make the bitmap.
Dim wid As Integer = Me.Width
Dim hgt As Integer = Me.Height
Dim bm As New Bitmap(wid, hgt)
Draw the form onto the bitmap.
Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
Make a smaller bitmap without borders.
wid = Me.ClientSize.Width
hgt = Me.ClientSize.Height
Dim bm2 As New Bitmap(wid, hgt)
Get the offset from the windows corner to its client
areas corner.
Dim pt As New Point(0, 0)
pt = PointToScreen(pt)
Dim dx As Integer = pt.X - Me.Left
Dim dy As Integer = pt.Y - Me.Top
Copy the part of the original bitmap that we want
into the bitmap.
Dim gr As Graphics = Graphics.FromImage(bm2)
gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), GraphicsUnit.Pixel)
Return bm
End Function
Work Smarter Not Harder
View the full article
All the New are throwing the Error. Private Sub Save_Image()
Try
Dim img As Image = GetFormImage(True)
img.Save("image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
Me.Text = ex.Message
End Try
End Sub
Private Function GetFormImage(ByVal include_borders As Boolean) As Bitmap
Make the bitmap.
Dim wid As Integer = Me.Width
Dim hgt As Integer = Me.Height
Dim bm As New Bitmap(wid, hgt)
Draw the form onto the bitmap.
Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
Make a smaller bitmap without borders.
wid = Me.ClientSize.Width
hgt = Me.ClientSize.Height
Dim bm2 As New Bitmap(wid, hgt)
Get the offset from the windows corner to its client
areas corner.
Dim pt As New Point(0, 0)
pt = PointToScreen(pt)
Dim dx As Integer = pt.X - Me.Left
Dim dy As Integer = pt.Y - Me.Top
Copy the part of the original bitmap that we want
into the bitmap.
Dim gr As Graphics = Graphics.FromImage(bm2)
gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), GraphicsUnit.Pixel)
Return bm
End Function
Work Smarter Not Harder
View the full article