0

你好,这次我的问题与这段代码有关,我使用的是 Visual Studio beta 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

附加信息:GDI+ 中的一般错误。

如果有这个异常的处理程序,程序可以安全地继续。

4

2 回答 2

0

您是否要捕获屏幕?为什么不使用 VS 的类来捕获屏幕?

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

于 2012-07-13T08:11:29.153 回答
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
于 2012-07-13T08:22:07.847 回答