Vb.net PRTSC(屏幕截图) - 错误

时间:2012-07-13 08:08:16

标签: vb.net screen bmp take

你好我的问题这一次它与这段代码有关,即时通讯使用视觉工作室测试版2012,我似乎无法找到问题,如果你们可以帮助我生病了欣赏它

Public Class Form1

    Private Sub fullScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fullScreen.Click
        SendKeys.SendWait("^{PRTSC}")
        Dim clip As IDataObject = Clipboard.GetDataObject()
        If clip.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            Dim screenCapture As Bitmap = CType(clip.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
            screenCapture.Save("C:\fullScreenCapture.bmp")
        End If
        Clipboard.Clear()
    End Sub
End Class

错误:

A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll

其他信息:错误genéricoenGDI +。

如果存在此异常的处理程序,则可以安全地继续该程序。

2 个答案:

答案 0 :(得分:0)

你想要捕捉屏幕吗?为什么不使用VS'类捕获屏幕?

http://forum.codecall.net/topic/51761-creating-a-screen-shot-tool-vbnet

答案 1 :(得分:0)

使用以下内容可以更轻松地拍摄屏幕截图(根据我的经验,发送密钥总是被击中和遗漏)

Private Function TakeScreenShot() As Bitmap
    Dim scrn As Screen = Screen.FromControl(Me)
    Dim screenSize As Size = New Size(scrn.Bounds.Width, scrn.Bounds.Height)
    Dim screenGrab As New Bitmap(screenSize.Width, screenSize.Height)
    Dim g As Graphics = Graphics.FromImage(screenGrab)
    g.CopyFromScreen(New Point(scrn.Bounds.X, scrn.Bounds.Y), New Point(0, 0), screenSize)
    Return screenGrab
End Function