单击时捕获并保存屏幕截图-Windows C#
首先,很抱歉问了这么长的问题,但我想确保我包括到目前为止我遇到的和做过的所有事情 我想为教程团队制作一个C#Windows应用程序,作为他们执行的枯燥手动任务的替代方案,即对执行教程步骤时出现的每个窗口按Alt+PrtSc,然后将其粘贴到ms paint中,以将图像保存到文件夹中,以便以后可以将其插入教程文档中 有不同的方法可以捕获桌面快照或仅捕获桌面的一部分。然而,我甚至可以在我的WinForms应用程序中拍摄控件的快照;一旦你点击并保存任何窗口的屏幕截图(连同鼠标指针),结果是有点棘手 我遇到过一篇文章,其中详细介绍了如何使用Win32 API捕获和保存屏幕截图。在后文中,我们讨论了如何仅使用.NET Framework来保存桌面的一部分,它工作得很好,但这并不是我所需要的。我确实遇到过一些免费软件和其他商业软件,它们做的更多,也有一点,但我更喜欢做一些简单和定制的东西 现在,我的表单有一个浏览按钮来选择一个文件夹(将图像保存到)和另一个名为开始的按钮。单击时,其名称更改为STOP(停止),并保持按下状态(直到再次单击停止) 比如说,团队必须准备一个软件的安装教程,向导的欢迎屏幕就打开了。应用程序启动后,当您不断单击“继续”、“我接受”、“下一步”等按钮时,应保存安装向导每个窗口的图像(连同鼠标指针)。。。下一步完成 我希望我能解释清楚。任何帮助都将不胜感激。提前谢谢单击时捕获并保存屏幕截图-Windows C#,c#,winapi,window,screenshot,mouse-pointer,C#,Winapi,Window,Screenshot,Mouse Pointer,首先,很抱歉问了这么长的问题,但我想确保我包括到目前为止我遇到的和做过的所有事情 我想为教程团队制作一个C#Windows应用程序,作为他们执行的枯燥手动任务的替代方案,即对执行教程步骤时出现的每个窗口按Alt+PrtSc,然后将其粘贴到ms paint中,以将图像保存到文件夹中,以便以后可以将其插入教程文档中 有不同的方法可以捕获桌面快照或仅捕获桌面的一部分。然而,我甚至可以在我的WinForms应用程序中拍摄控件的快照;一旦你点击并保存任何窗口的屏幕截图(连同鼠标指针),结果是有点棘手 我遇
- GJ
; open destination folder
destinationFolder:=GadWinDestinationFolder()
ifExist %destinationFolder%
{
Run explorer.exe %destinationFolder%
sleep 1000
}
;; shows an opening message
; TBD could be on a message box to let user choose/acknowledge
ShowStatus("Capture is Enabled.`n<Pause/Break> to toggle on/off", 10000)
; *** ,% <space> func() is autohotkey magic for interpolate a function here ***
RunWait,% GadWinExe()
sleep 5000
capturing:=true
Return
; ~ means pass the click & position through to the system
; This allows drag screens to work, while Send LButton does not
; TBS look at MouseGetPos + MouseClickDrag
~LButton::
Capture()
;Send {LButton}
return
~RButton::
Capture()
;Send {RButton}
Return
Capture()
{
global capturing
if (capturing)
{
;ClipSaved:=ClipboardAll ; Save the entire clipboard to a variable
; this may be whacking the clipboard
; alt -prt scrn
Send {PRINTSCREEN}
ShowStatus("Captured to " GadWinDestinationFolder() "`nPress <Pause/Break> to toggle.", 3000)
;Clipboard:=ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
;ClipSaved:= ; Free the memory in case the clipboard was very large.
}
Else
{
dp("Capture is off`nPress <Pause/Break> to toggle.")
}
Return
}
PAUSE:: CaptureToggle(2000)
CaptureToggle(delay)
{
global capturing
Suspend OFF
capturing:=!capturing
If (capturing)
{
ShowStatus("Capture Enabled.", delay)
}
Else
{
ShowStatus("Capture Disabled.", delay)
;Suspend
}
Return
}
GadWinExe()
{
RegRead, exeFolder, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Gadwin PrintScreen, InstallLocation
Return exeFolder "\PrintScreen.exe"
}
GadWinDestinationFolder()
{
; Gadwin specific
RegRead, CaptureDir, HKEY_CURRENT_USER, Software\Gadwin Systems\PrintScreen\Destination, CaptureDir
Return CaptureDir
}
ShowStatus(msg, time)
{
ShowTrayTip("ClickScreen", msg, time)
}
; Generic Show and Remove Tray Tip
ShowTrayTip(title, msg, time)
{
; 7/7/2011 Win Server 2008 - 30 seems to have no effect
TrayTip, %title%, %msg%, 30, 1
SetTimer, RemoveTrayTip, %time% ; used to ensure tip is taken down
dp(msg)
Return
; The Traytip does not disappear quickly without this
; 7/7/2011 Win Server 2008 - tip disappears after 4 seconds anyway if the script continues to run
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
dp("TrayTip off")
Return
}
FindAndRun(exeName)
{
; Here I get to define the folders to search
ProgramFolders:="P:\Program Files,C:\Program Files,C:\Program Files (x86)"
Loop, parse, ProgramFolders, `,
{
IfExist, %A_LoopField%\%exeName%
{
Run %A_LoopField%\%exeName%
Return
}
}
MsgBox File %exeName% not found
}
dp(Msg)
{
OutputDebug %A_ScriptName% %Msg%
}
希望这会让您开始尝试键入以下内容以保存屏幕截图:
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics Graphics1;
Bitmap Bitmap1 = new Bitmap(screenWidth, screenHeight);
Graphics1 = Graphics.FromImage(Bitmap1);
Graphics1.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
Bitmap1.Save(@"c:\ScreenShot1.bmp); //Place that you want to save screenshot
顺便提一下令我惊讶的是(在进一步阅读之后),我在Win7中发现了一个名为psr.exe的内置工具,它与我上面提到的完全相同,但它将输出保存在.mht中,并且图像在鼠标单击区域附近有一些浮华的图形。Screen.PrimaryScreen在哪个名称空间中?需要哪些参考/nuget包?
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
Graphics Graphics1;
Bitmap Bitmap1 = new Bitmap(screenWidth, screenHeight);
Graphics1 = Graphics.FromImage(Bitmap1);
Graphics1.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
Bitmap1.Save(@"c:\ScreenShot1.bmp); //Place that you want to save screenshot