从 Windows 中的命令行截取屏幕截图

Žel*_*pin 57 windows screenshot command-line

我正在寻找一种从命令行截取整个屏幕截图的方法。操作系统是Windows。像这样的东西:

C:\>screenshot.exe screen1.png
Run Code Online (Sandbox Code Playgroud)

小智 45

这个问题已经得到了回答,但我想我也会把它扔进去。NirCmd(免费软件,遗憾的是,不是开源的)可以从命令行截取屏幕截图,并结合它可以执行的许多其他功能。

从命令行在 nircmd.exe 的目录中运行此命令,或者将其复制到 system32 文件夹中:

nircmd.exe savescreenshot screen1.png
Run Code Online (Sandbox Code Playgroud)

做你想做的。你也可以像这样延迟它:

nircmd.exe cmdwait 2000 savescreenshot screen1.png
Run Code Online (Sandbox Code Playgroud)

这将等待 2000 毫秒(2 秒),然后捕获并保存屏幕截图。


Dav*_*llo 28

下载imagemagick。包括许多命令行图像处理工具。 导入允许您捕获部分或全部屏幕并将图像保存到文件中。例如,要将整个屏幕保存为 jpeg:

import -window root screen.jpeg
Run Code Online (Sandbox Code Playgroud)

如果要使用鼠标在窗口内单击或选择屏幕区域并保存 aa png,只需使用:

import box.png
Run Code Online (Sandbox Code Playgroud)

  • 这似乎不适用于 Windows。我收到有关找不到文件的 X 服务器错误。 (15认同)
  • @BinaryPhile 是的,我认为这仅适用于在 Cygwin 上运行的 X 服务器。 (2认同)

npo*_*aka 28

它可以在没有外部工具的情况下完成(你只需要安装 .net 框架,它默认安装在 vista 及以上的所有东西上) - screenCapture.bat。它是一个自编译的 C# 程序,您可以将输出保存为几种格式并仅捕获活动窗口或整个屏幕:

screenCapture- captures the screen or the active window and saves it to a file
Usage:
screenCapture  filename.format [WindowTitle]

filename - the file where the screen capture will be saved
format - Bmp,Emf,Exif,Gif,Icon,Jpeg,Png,Tiff and are supported - default is bmp
WindowTitle - instead of capturing the whole screen will capture the only a window with the given title if there's such
Run Code Online (Sandbox Code Playgroud)

例子:

call screenCapture notepad.jpg "Notepad"
call screenCapture screen.png
Run Code Online (Sandbox Code Playgroud)

  • 绝对是最好的解决方案。超小9K!这是 ImageMagick (25 Mb) 大小的 0.04%。它使用内置的 Windows 功能。比此页面上的所有其他解决方案都要小。最好的事物! (3认同)
  • 这个 BAT/C# 脚本效果很好。我仍然更喜欢构建 EXE,并从 BAT 中调用它,但这可行。我还学习了一些 C# 和 BAT 命令。 +1 (2认同)

小智 13

其他建议很好——您也可以尝试 MiniCap,它是免费的,并具有一些其他功能,例如灵活的文件命名和一些不同的捕获模式:http : //www.donationcoder.com/Software/Mouser/MiniCap/index.html

(免责声明:我是 MiniCap 的作者)。


小智 11

试试IrfanView

您可以通过命令行运行它。您可以指定要捕获的窗口 - 例如整个窗口或仅当前/活动窗口 - 您还可以进行一些基本编辑,例如锐化、裁剪或调整图像大小。

下面是命令行选项,特别有趣的是

i_view32 /capture=0 /convert=wholescreen.png
Run Code Online (Sandbox Code Playgroud)


Jam*_*mes 7

您可以尝试使用boxcutter工具:

usage: boxcutter [OPTIONS] [OUTPUT_FILENAME]

Saves a bitmap screenshot to 'OUTPUT_FILENAME' if given.  Otherwise, 
screenshot is stored on clipboard by default.

OPTIONS
  -c, --coords X1,Y1,X2,Y2    capture the rectange (X1,Y1)-(X2,Y2)
  -f, --fullscreen            fullscreen screenshot
  -v, --version               display version information
  -h, --help                  display help message
Run Code Online (Sandbox Code Playgroud)


小智 7

Screenshot-cmd截取桌面或窗口标题选择的任何窗口的屏幕截图。也可以选择矩形进行捕获。结果存储为 png 文件。(上次更新于 2011 年)

选项:
    -wt WINDOW_TITLE
            选择具有此标题的窗口。
            标题不得包含空格 (" ")。
    -wh WINDOW_HANDLE
            通过它的句柄选择窗口
            (表示为十六进制字符串 - fe "0012079E") 
    -rc 左上右下
            作物来源。如果没有提供 WINDOW_TITLE
            (0,0) 是桌面的左上角,
            否则如果 WINDOW_TITLE 匹配桌面窗口
            (0,0) 是它的左上角。
    -o 文件名
            输出文件名,如果没有,图像将被保存
            作为当前工作目录中的“screenshot.png”。
    -H
            显示此帮助信息。

灵感来自:http : //blog.mozilla.com/ted/2009/02/05/command-line-screenshot-tool-for-windows/


Was*_*sif 7

您可以使用此处找到的 PowerShell 代码:

[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
   $bmp = New-Object Drawing.Bitmap $bounds.width, >$bounds.height
   $graphics = [Drawing.Graphics]::FromImage($bmp)

   $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)

   $bmp.Save($path)

   $graphics.Dispose()
   $bmp.Dispose()
}

$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\screenshot.png"
Run Code Online (Sandbox Code Playgroud)


alp*_*989 5

您可以使用Pillowpython 库来截取主监视器的屏幕截图

第一步:安装枕头:

pip install -user pillow
Run Code Online (Sandbox Code Playgroud)

Step2:使用以下代码截取屏幕截图:

from PIL import ImageGrab
img = ImageGrab.grab()
img.save('screenshot.bmp')
Run Code Online (Sandbox Code Playgroud)