Vb.Net应用程序屏幕捕获并将其另存为pdf

时间:2018-02-14 21:57:01

标签: vb.net screen capture

我有这个小应用程序捕获屏幕并将其保存为pdf。我在我的PC上运行这个应用程序,它有1080P主显示器和1080P电视作为扩展显示器。当我将应用程序放在扩展电视显示器(全屏模式)时,它不会捕获整个屏幕。它只捕获屏幕的1/4。但我想捕捉整个屏幕。我该如何解决。请帮忙

这是代码;

 Private Sub SaveForm_shift1()

    Dim yesterday As String = DateTime.Now.ToString("yyyy-MM-dd")
    Dim filePath As String = "C:\Autodesk" + yesterday + ".jpg"

    Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
    Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
    gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
    Try
        gfxScreenshot.Dispose()
        ' Save the screenshot   
        bmpScreenshot.Save(filePath)
        saveToPdf_shift1(filePath)
        deleteImg(filePath)
    Catch ex As Exception
        MessageBox.Show(ex.ToString)
    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

使用此功能获取包含所有屏幕的位图

Public Function GetScreenShot() As Bitmap
    Dim bmp As Bitmap = New Bitmap(Screen.AllScreens.Sum(Function(s As Screen) s.Bounds.Width),
                                   Screen.AllScreens.Max(Function(s As Screen) s.Bounds.Height))
    Dim gfx As Graphics = Graphics.FromImage(bmp)
    gfx.CopyFromScreen(New Point(0, 0), New Point(0, 0), bmp.Size)

    Return bmp
End Function

如果您有奇怪的交错屏幕位置,则生成的位图中的空白区域将为黑色。