我想在我的代码中捕获屏幕以获取图像 - 就像使用键盘上的"打印屏幕"按钮一样.
有谁知道如何做到这一点?我没有起点.
我想要一个相对无黑客的方式来做这个,任何想法?例如,以下截图不包括半透明窗口:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Text = "Opaque Window"
Dim win2 As New Form
win2.Opacity = 0.5
win2.Text = "Tranparent Window"
win2.Show()
win2.Top = Top + 50
win2.Left = Left() + 50
Dim bounds As Rectangle = System.Windows.Forms.Screen.GetBounds(Point.Empty)
Using bmp As Bitmap = New Bitmap(bounds.Width, bounds.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size)
End Using
bmp.Save("c:\temp\scn.gif")
End Using
Process.Start(New Diagnostics.ProcessStartInfo("c:\temp\scn.gif") With {.UseShellExecute = True})
End Sub
End …Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,它以一定的时间间隔拍摄桌面的屏幕截图.
代码:
String nme = "";
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
nme = DateTime.Now.ToString();
printscreen.Save(@"F:\Temp\printScre.jpg", ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
我们需要我们的应用程序的屏幕截图进行单元测试.CaptureScreen()并CopyFromScreen()以某种方式忽略应用程序并返回空桌面的图片.所以我们写这个来假冒PrtScn击键:
public static Bitmap GetAltScreenshot()
{
Clipboard.Clear();
SendKeys.SendWait("{PRTSC}");
while (!Clipboard.ContainsImage())
{
Thread.Sleep(500);
}
return new Bitmap(Clipboard.GetImage());
}
Run Code Online (Sandbox Code Playgroud)
Alt不是击键的一部分,所以这应该返回整个屏幕的位图.然而,不知何故,这个片段只返回聚焦窗口.哪个好,这解决了我们的问题 - 但我们不明白如何.
为什么这会只返回聚焦窗口而不是整个显示器的镜头?
我正在使用c#在IE中打开一个网页
码:
Process.Start("IExplore.exe", "www.northwindtraders.com");
但是,如何使用以下特征调整页面大小: toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width='622', height='582'
我想在我的应用程序中截取屏幕截图,并希望将其保存在具有唯一名称的应用程序的本地文件夹中.所以请帮帮我.
c# ×6
.net ×3
screenshot ×3
automation ×1
sdk ×1
sendkeys ×1
uwp ×1
vb.net ×1
windows ×1
winforms ×1