我有两种形式。
- 表格 1 包含我需要截图的内容
- 表格 2 包含图形绘制(该表格始终位于顶部但透明)。
我需要对第一个表单进行屏幕截图,而不将其放在表单 2 之上,也不包含表单 2 中的内容。
这是我正在处理的一些问题,我正在努力修复。
Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
Dim Screenshot As New Bitmap(Control.Width, Control.Height)
Control.DrawToBitmap(Screenshot, New Rectangle(0, 0, Control.Width, Control.Height))
Return Screenshot
End Function
此函数不起作用,因为 Control.drawtoBitmap 未设置 IMG 的值。
IMG 是空白的,并以纯白色图像的形式返回。
这个函数的调用是这样的
TakeScreenShot(form1.webbrowser1).Save("c:\Screenshot.png",
System.Drawing.Imaging.ImageFormat.Png)
所有帮助将不胜感激。
更换你的TakeScreenShot
与此功能:
Private Function TakeScreenShot(ByVal Control As Control) As Bitmap
Dim tmpImg As New Bitmap(Control.Width, Control.Height)
Using g As Graphics = Graphics.FromImage(tmpImg)
g.CopyFromScreen(Control.PointToScreen(New Point(0, 0)), New Point(0, 0), New Size(Control.Width, Control.Height))
End Using
Return tmpImg
End Function
这应该可行,但是如果由于某种原因不起作用,问题可能是顶部的透明表单。
您可以用完全相同的方式调用它。
祝你好运 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)