vb.net 将表单另存为图像(截图)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22676601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Save form as image (screenshot)
提问by user3466723
I have 2 forms.
我有2个表格。
- Form 1 contains the content that i need a screenshot of
- Form 2 contains graphics drawing (this form is always on top but transparent).
- 表格 1 包含我需要截图的内容
- 表格 2 包含图形绘制(此表格始终在顶部但透明)。
I need to screen shot the first form without making it on top of form 2 as well as without including content from form 2.
我需要对第一个表单进行屏幕截图,而不是将它放在表单 2 的顶部,也不包括来自表单 2 的内容。
here is some what i am working with, which i am trying to fix.
这是我正在使用的一些内容,我正在尝试解决这些问题。
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
This function is not working because Control.drawtoBitmap is not setting the value of IMG.
此函数不起作用,因为 Control.drawtoBitmap 未设置 IMG 的值。
IMG is blank and being returned as a plain white image.
IMG 是空白的并作为纯白色图像返回。
The calling of this function is this
这个函数的调用是这样的
TakeScreenShot(form1.webbrowser1).Save("c:\Screenshot.png",
System.Drawing.Imaging.ImageFormat.Png)
All help would be appreciated.
所有帮助将不胜感激。
回答by Piratica
Replace your TakeScreenShotfunction with this:
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
This should work, however if for some reason it doesn't the problem might be the transparent form on top.
You can call it in excactly the same way.
Good luck :)
这应该可行,但是如果由于某种原因它不是问题,那么问题可能出在顶部的透明表单上。
您可以以完全相同的方式调用它。
祝你好运 :)

