繁体   English   中英

如何在vb.net,WPF中截取屏幕截图?

[英]How to take screenshots in vb.net, WPF?

因此,正如标题所述,我如何在vb.net,WPF中截屏,vb.net的常规代码用于截屏

 Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
screenshot.Save("d:\\dcap.jpg", Imaging.ImageFormat.Bmp)

不起作用,因为我无法在WPF中定义“图形”,也无法像在vb.net中一样定义绘图位图

所以,我能做什么?

您需要向System.Drawing添加引用和Imports指令。

我放弃了“自动”捕获屏幕(例如,由于未处理的异常)-太不一致了。

我曾经使用屏幕捕获来让用户用来记录他们遇到问题的表单(下面的异常处理程序中的代码。)现在,我启动了SnippingTool-使用户知道如何以任何方式使用该工具。

Friend Sub PrintScrn(ByVal ffrm As System.Windows.Forms.Form)
    Try
        If Not Environment.Is64BitProcess Then
            Process.Start("C:\Windows\sysnative\SnippingTool.exe")
        Else
            Process.Start("C:\Windows\system32\SnippingTool.exe")
        End If
    Catch ex As Exception
        If vbOK = MsgBox("Replace clipboard contents with an image of the form?", MsgBoxStyle.DefaultButton2 + MsgBoxStyle.OkCancel) Then
            Dim wid As Integer = ffrm.Width
            Dim hgt As Integer = ffrm.Height
            Dim bm As New Bitmap(wid, hgt)
            ' Draw the form onto a bitmap.
            ffrm.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
            My.Computer.Clipboard.SetImage(bm)
            MsgBox("Form image now on clipboard. Use Ctrl-V to paste into Word, Notes, Paint, etc.")
        End If
    End Try
End Sub

上下文:Vb.Net WinForm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM