从http://www.vbforums.com/showthread.php?t=385497下载“ScreenCapture.vb”, 使用CaptureDeskTopRectangle
,但你不应该用你的面板的位置,因为它 参考面板家长,你应该使用yourpanel.PointToScreen()
识别正确 矩形。 问候..
UPDATE:
检查了这一点,你会去喜欢它,我similute你的情况下,它的工作:
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Try
Using fl As New SaveFileDialog
fl.Filter = "PNG images|*.png"
If fl.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim sc As New screencapture
Dim pt = WebBrowser1.Parent.PointToScreen(WebBrowser1.Location)
Dim rec As New Rectangle(pt.X, pt.Y, WebBrowser1.Width, WebBrowser1.Height)
Application.DoEvents()
Threading.Thread.Sleep(500)
Using bmp As Bitmap = sc.CaptureDeskTopRectangle(rec, WebBrowser1.Width, WebBrowser1.Height)
bmp.Save(fl.FileName, System.Drawing.Imaging.ImageFormat.Png)
End Using
End If
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
更新2:
在形式:
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Try
Using fl As New SaveFileDialog
fl.Filter = "PNG images|*.png"
If fl.ShowDialog = Windows.Forms.DialogResult.OK Then
JSsetTimeout.SetTimeout(Me, "TakeShot", 1500, fl.FileName)
End If
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub TakeShot(ByVal FilePath As String)
Try
Application.DoEvents()
Dim sc As New screencapture
Dim pt = WebBrowser1.Parent.PointToScreen(WebBrowser1.Location)
Dim rec As New Rectangle(pt.X, pt.Y, WebBrowser1.Width, WebBrowser1.Height)
Using bmp As Bitmap = sc.CaptureDeskTopRectangle(rec, WebBrowser1.Width, WebBrowser1.Height)
bmp.Save(FilePath, System.Drawing.Imaging.ImageFormat.Png)
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
创建一个时间延迟添加下面的类:
Public Class JSsetTimeout
Public res As Object = Nothing
Dim WithEvents tm As Timer = Nothing
Dim _MethodName As String
Dim _args() As Object
Dim _ClassInstacne As Object = Nothing
Public Shared Sub SetTimeout(ByVal ClassInstacne As Object, ByVal obj As String, ByVal TimeSpan As Integer, ByVal ParamArray args() As Object)
Dim jssto As New JSsetTimeout(ClassInstacne, obj, TimeSpan, args)
End Sub
Public Sub New(ByVal ClassInstacne As Object, ByVal obj As String, ByVal TimeSpan As Integer, ByVal ParamArray args() As Object)
If obj IsNot Nothing Then
_MethodName = obj
_args = args
_ClassInstacne = ClassInstacne
tm = New Timer With {.Interval = TimeSpan, .Enabled = False}
AddHandler tm.Tick, AddressOf tm_Tick
tm.Start()
End If
End Sub
Private Sub tm_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tm.Tick
tm.Stop()
RemoveHandler tm.Tick, AddressOf tm_Tick
If Not String.IsNullOrEmpty(_MethodName) AndAlso _ClassInstacne IsNot Nothing Then
res = CallByName(_ClassInstacne, _MethodName, CallType.Method, _args)
Else
res = Nothing
End If
End Sub
End Class
[WebBrowser.DrawtoBitmap()为少数网站生成空白图像的可能重复](http://stackoverflow.com/questions/5351830/webbrowser-drawtobitmap-generating-blank-images-for-few-sites-consistently ) – 2012-02-16 02:32:48
问题是'WebBrowser'控件是一个ActiveX控件,它不支持'[DrawToBitmap']方法按照[文档](http://msdn.microsoft.com/en-我们/库/ system.windows.forms.control.drawtobitmap.aspx)。 – 2012-02-16 02:33:44
使用IHTMLElementRender:http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/6354ec94-503b-45b6-be2f-94bbd3bc460a – 2012-02-16 04:01:55