替代方法:我可以使用以下代码将控件保存为位图,而不是使用 Ink API 保存图像。
它确实有一些缺点(例如一旦保存它就不可编辑,但这对于这种情况来说是件好事)。
Public Shared Sub SaveAsBitmap(ByVal control As Windows.Forms.Control, ByVal fileName As String, ByVal imageFormat As Imaging.ImageFormat)
Dim bmp As Bitmap = ConvertToBitmap(control)
bmp.Save(fileName, imageFormat)
bmp.Dispose()
End Sub
Public Shared Function ConvertToBitmap(ByVal control As Windows.Forms.Control) As Bitmap
//get the instance of the graphics from the control
Dim g As Graphics = control.CreateGraphics()
//new bitmap object to save the image
Dim bmp As New Bitmap(control.Width, control.Height)
//Drawing control to the bitmap
control.DrawToBitmap(bmp, New Rectangle(0, 0, control.Width, control.Height))
Return bmp
End Function