- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此帖子中提供了另一种截图工具解决方案:.NET Equivalent of Snipping Tool
现在有必要使其适用于选定的屏幕(在多显示器系统上)。
代码已相应修改:
Public Class SnippingTool
Private Shared _Screen As Screen
Private Shared BitmapSize As Size
Private Shared Graph As Graphics
Public Shared Function Snip(ByVal screen As Screen) As Image
_Screen = screen
Dim bmp As New Bitmap(screen.Bounds.Width, screen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
Dim gr As Graphics = Graphics.FromImage(bmp)
Graph = gr
gr.SmoothingMode = Drawing2D.SmoothingMode.None '###
BitmapSize = bmp.Size
Using snipper = New SnippingTool(bmp)
snipper.Location = New Point(screen.Bounds.Left, screen.Bounds.Top)
If snipper.ShowDialog() = DialogResult.OK Then
Return snipper.Image
End If
End Using
Return Nothing
End Function
Public Sub New(ByVal screenShot As Image)
InitializeComponent()
Me.BackgroundImage = screenShot
Me.ShowInTaskbar = False
Me.FormBorderStyle = FormBorderStyle.None
'Me.WindowState = FormWindowState.Maximized
Me.DoubleBuffered = True
End Sub
Public Property Image() As Image
Get
Return m_Image
End Get
Set(ByVal value As Image)
m_Image = Value
End Set
End Property
Private m_Image As Image
Private rcSelect As New Rectangle()
Private pntStart As Point
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
' Start the snip on mouse down
If e.Button <> MouseButtons.Left Then
Return
End If
pntStart = e.Location
rcSelect = New Rectangle(e.Location, New Size(0, 0))
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
' Modify the selection on mouse move
If e.Button <> MouseButtons.Left Then
Return
End If
Dim x1 As Integer = Math.Min(e.X, pntStart.X)
Dim y1 As Integer = Math.Min(e.Y, pntStart.Y)
Dim x2 As Integer = Math.Max(e.X, pntStart.X)
Dim y2 As Integer = Math.Max(e.Y, pntStart.Y)
rcSelect = New Rectangle(x1, y1, x2 - x1, y2 - y1)
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
' Complete the snip on mouse-up
If rcSelect.Width <= 0 OrElse rcSelect.Height <= 0 Then
Return
End If
Image = New Bitmap(rcSelect.Width, rcSelect.Height)
Using gr As Graphics = Graphics.FromImage(Image)
gr.DrawImage(Me.BackgroundImage, New Rectangle(0, 0, Image.Width, Image.Height), rcSelect, GraphicsUnit.Pixel)
End Using
DialogResult = DialogResult.OK
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
' Draw the current selection
Using br As Brush = New SolidBrush(Color.FromArgb(120, Color.White))
Dim x1 As Integer = rcSelect.X
Dim x2 As Integer = rcSelect.X + rcSelect.Width
Dim y1 As Integer = rcSelect.Y
Dim y2 As Integer = rcSelect.Y + rcSelect.Height
e.Graphics.FillRectangle(br, New Rectangle(0, 0, x1, Me.Height))
e.Graphics.FillRectangle(br, New Rectangle(x2, 0, Me.Width - x2, Me.Height))
e.Graphics.FillRectangle(br, New Rectangle(x1, 0, x2 - x1, y1))
e.Graphics.FillRectangle(br, New Rectangle(x1, y2, x2 - x1, Me.Height - y2))
End Using
Using pen As New Pen(Color.Red, 3)
e.Graphics.DrawRectangle(pen, rcSelect)
End Using
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
' Allow canceling the snip with the Escape key
If keyData = Keys.Escape Then
Me.DialogResult = DialogResult.Cancel
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
Me.Size = New Size(_Screen.Bounds.Width, _Screen.Bounds.Height)
Dim area = _Screen.WorkingArea
Graph.CopyFromScreen(area.X, area.Y, area.Y, area.Y, BitmapSize)
End Sub
End Class
但它拒绝按预期工作。截图不会出现在所选屏幕上,而是出现在第一个屏幕上,无论“截图”功能中的“屏幕”参数如何。如何让它正常工作?
更新:最新的 snipper 版本出现在正确的屏幕上,但为空白。
UPDATE X2:上面的代码已经更新以反射(reflect)最新版本,现在可以正常工作。
最佳答案
LoveDotNet,我相信你的源代码有一个小问题,如下一行:
Graph.CopyFromScreen(area.X, area.Y, area.Y, area.Y, BitmapSize)
应该是:
Graph.CopyFromScreen(area.X, area.Y, 0, 0, BitmapSize)
另外,给任何想要使用此代码的人一个快速提示,您可以像下面这样调用它:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim img As Image = SnippingTool.Snip(Screen.AllScreens(0)) 'Set to (1) for secondary monitor'
End Sub
此外,当您创建 SnippingTool 表单时,请务必将 StartPosition
属性更改为 Manual
。
大编辑:
我做了一些工作来一次支持多个显示器,这不需要开发人员选择要使用的显示器(这克隆了“截图工具”更接近一点)。
基本上,我遍历所有屏幕以找到最小的 X
和 Y
坐标,以及最大的 Right
和 底部
,这让我们可以评估“虚拟监视器”的完整大小:
我已经用我的配置测试了它:
主要 1280x800
二级 1280x1024 w/-224 X 偏移
代码:
'SnippingTool Code: Place this in a new form (set the StartUp Property to Manual)'
Public Class SnippingTool
Private Shared _Screen As Screen
Private Shared BitmapSize As Size
Private Shared Graph As Graphics
Private Structure MultiScreenSize
Dim minX As Integer
Dim minY As Integer
Dim maxRight As Integer
Dim maxBottom As Integer
End Structure
Private Shared Function FindMultiScreenSize() As MultiScreenSize
Dim minX As Integer = Screen.AllScreens(0).Bounds.X
Dim minY As Integer = Screen.AllScreens(0).Bounds.Y
Dim maxRight As Integer = Screen.AllScreens(0).Bounds.Right
Dim maxBottom As Integer = Screen.AllScreens(0).Bounds.Bottom
For Each aScreen As Screen In Screen.AllScreens
If aScreen.Bounds.X < minX Then
minX = aScreen.Bounds.X
End If
If aScreen.Bounds.Y < minY Then
minY = aScreen.Bounds.Y
End If
If aScreen.Bounds.Right > maxRight Then
maxRight = aScreen.Bounds.Right
End If
If aScreen.Bounds.Bottom > maxBottom Then
maxBottom = aScreen.Bounds.Bottom
End If
Next
Dim m_MultiScreenSize As MultiScreenSize
With m_MultiScreenSize
.minX = minX
.minY = minY
.maxBottom = maxBottom
.maxRight = maxRight
End With
Return m_MultiScreenSize
End Function
Public Shared Function Snip() As Image
Dim m_MultiScreenSize As MultiScreenSize = FindMultiScreenSize()
Dim bmp As New Bitmap(m_MultiScreenSize.maxRight - m_MultiScreenSize.minX, _
m_MultiScreenSize.maxBottom - m_MultiScreenSize.minY, _
System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
Dim gr As Graphics = Graphics.FromImage(bmp)
Graph = gr
gr.SmoothingMode = Drawing2D.SmoothingMode.None
BitmapSize = bmp.Size
Using snipper = New SnippingTool(bmp)
snipper.Location = New Point(m_MultiScreenSize.minX, m_MultiScreenSize.minY)
If snipper.ShowDialog() = DialogResult.OK Then
Return snipper.Image
End If
End Using
Return Nothing
End Function
Public Sub New(ByVal screenShot As Image)
InitializeComponent()
Me.BackgroundImage = screenShot
Me.ShowInTaskbar = False
Me.FormBorderStyle = FormBorderStyle.None
Me.DoubleBuffered = True
End Sub
Public Property Image() As Image
Get
Return m_Image
End Get
Set(ByVal value As Image)
m_Image = Value
End Set
End Property
Private m_Image As Image
Private rcSelect As New Rectangle()
Private pntStart As Point
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
' Start the snip on mouse down'
If e.Button <> MouseButtons.Left Then
Return
End If
pntStart = e.Location
rcSelect = New Rectangle(e.Location, New Size(0, 0))
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
' Modify the selection on mouse move'
If e.Button <> MouseButtons.Left Then
Return
End If
Dim x1 As Integer = Math.Min(e.X, pntStart.X)
Dim y1 As Integer = Math.Min(e.Y, pntStart.Y)
Dim x2 As Integer = Math.Max(e.X, pntStart.X)
Dim y2 As Integer = Math.Max(e.Y, pntStart.Y)
rcSelect = New Rectangle(x1, y1, x2 - x1, y2 - y1)
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
' Complete the snip on mouse-up'
If rcSelect.Width <= 0 OrElse rcSelect.Height <= 0 Then
Return
End If
Image = New Bitmap(rcSelect.Width, rcSelect.Height)
Using gr As Graphics = Graphics.FromImage(Image)
gr.DrawImage(Me.BackgroundImage, New Rectangle(0, 0, Image.Width, Image.Height), _
rcSelect, GraphicsUnit.Pixel)
End Using
DialogResult = DialogResult.OK
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
' Draw the current selection'
Using br As Brush = New SolidBrush(Color.FromArgb(120, Color.White))
Dim x1 As Integer = rcSelect.X
Dim x2 As Integer = rcSelect.X + rcSelect.Width
Dim y1 As Integer = rcSelect.Y
Dim y2 As Integer = rcSelect.Y + rcSelect.Height
e.Graphics.FillRectangle(br, New Rectangle(0, 0, x1, Me.Height))
e.Graphics.FillRectangle(br, New Rectangle(x2, 0, Me.Width - x2, Me.Height))
e.Graphics.FillRectangle(br, New Rectangle(x1, 0, x2 - x1, y1))
e.Graphics.FillRectangle(br, New Rectangle(x1, y2, x2 - x1, Me.Height - y2))
End Using
Using pen As New Pen(Color.Red, 3)
e.Graphics.DrawRectangle(pen, rcSelect)
End Using
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
' Allow canceling the snip with the Escape key'
If keyData = Keys.Escape Then
Me.DialogResult = DialogResult.Cancel
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
Dim m_MultiScreenSize As MultiScreenSize = FindMultiScreenSize()
Me.Size = New Size(m_MultiScreenSize.maxRight - m_MultiScreenSize.minX, _
m_MultiScreenSize.maxBottom - m_MultiScreenSize.minY)
Graph.CopyFromScreen(m_MultiScreenSize.minX, m_MultiScreenSize.minY, 0, 0, BitmapSize)
End Sub
End Class
你可以这样调用它:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim img As Image = SnippingTool.Snip()
img.Save("C:\ScreenShot.png")
End Sub
关于.net - 使 .NET 截图工具与多个监视器兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4005910/
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
如何创建 iPhone 屏幕截图?当我打开 Xcode 时,我转到“窗口”>“管理器”,但没有可见的“设备”选项卡。我有一部操作系统为 3.1.2 的越狱手机。 最佳答案 在手机上,按住主页按钮并按
我一直在使用 UIGetScreenImage() 来获取 UIImagePickerController 的屏幕截图。基本上我使用相机覆盖层,然后当我拍摄屏幕截图时,我会看到相机预览显示的图像以及我
我想对我创建的面板进行屏幕截图,代码如下。任何人都可以告诉我为什么我没有得到。谢谢 public static final void makeScreenshot(JFrame argFram
我正在开发一个应用程序,它使用前置摄像头为使用该应用程序的人模拟一面镜子。我已经实现了一个“平视显示器”,它位于相机 View 的前面并显示一些东西。目前这很好用。现在我想实现一种每 5 秒截取一次屏
如何使用安卓模拟器截屏? 最佳答案 在 Eclipse 中打开 Devices View (Window -> Show View -> Other, Android -> Devices),右侧有一
我正在开发一个用于在设备中截取屏幕截图的应用程序。在这个应用程序中,我们可以在屏幕上绘制任何东西。为此,我使用 Canvas、Paint 和 Path 来执行此操作。 我正在使用此代码截取屏幕截图:
如何捕获屏幕并将其保存为 C 中的图像? 操作系统:Windows(XP 和 7) 谢谢 最佳答案 你试过了吗google ?这forum entry有一个示例,包含使用 Win32 API 的 C
我正在尝试使用这段代码: bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);
我想使用 php 创建网站缩略图(屏幕截图)。我有一个运行 centos 5.5 的专用服务器,所以我可以在上面安装软件。 我需要一个免费的解决方案来在生产服务器上创建网站的缩略图,而无需运行 X 服
我正在尝试截取在 lcdtv 上播放的 roku 应用程序的屏幕截图。 将您的 Roku 置于开发者模式。确认您的 Roku 的 IP 地址。 Side load your app to the Ro
UIImage* image = nil; UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0); {
我有一个 View Controller ,它通过按钮进入 TableView Controller 。 在 View Controller 中,导航栏是完全半透明的(如下面的屏幕截图所示)。在 Ta
我使用- (BOOL)presentPreviewAnimated:(BOOL)animated; 来加载文档,然后我想从文档中截取屏幕截图。所以我尝试 UIGraphicsBeginImageCon
我不知道如何使用 css (-fx-... :...) 将这种效果应用于 javaFX 2 中的文本字段; 我需要像屏幕截图中那样的东西。我有一个带有该背景的面板,我需要文本字段将其变暗一点(它看起来
我在我的 Windows 应用程序中使用 C++/Direct2D,我在 pRenderTarget->BeginDraw() 和 pRenderTarget->EndDraw() 之间绘制一些线条和
我正在尝试使用后台服务截取屏幕截图。此服务就像 Facebook chathead,但我希望它在我点击时截取屏幕截图。 我已经开发了一些代码,但它不起作用。我最后尝试的是: private void
我搜索了很多有关在 Android 上截取我的 OpenGL 对象的屏幕截图的信息,并提出了 this解决方案。它工作得很好,但在我的例子中,我在相机 View 之上有相机 View 和 opengl
我开始在 xcode 中编程,当我启动它时,xcode 会问我“你是谁”。有人知道需要做什么吗?谢谢! 截图: 最佳答案 Xcode 包含对 Git 的集成支持。你的屏幕截图是 Git 要求你设置你的
我需要对ARSCNView进行截图,类定义如下: public class SceneLocationView: ARSCNView, ARSCNViewDelegate { } 我正在按照以下方法完
我是一名优秀的程序员,十分优秀!