所以,正如标题所说我如何在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)
不起作用,因为我无法定义" Graphics"在WPF中,我也无法定义绘图位图,就像我通常在vb.net中那样做
那么,我能做什么?
答案 0 :(得分:1)
您需要向Imports
添加引用和System.Drawing
指令。
答案 1 :(得分:0)
我放弃了“自动”捕捉屏幕(例如来自未处理的例外) - 太不一致了。
我过去常常使用屏幕截图来记录他们遇到问题的表单(下面的异常处理程序中的代码。)现在我启动了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