如何在 Windows 上使用 Ruby 捕获屏幕的一部分? [英] How to capture a part of a screen using Ruby on Windows?
问题描述
我想用 Ruby 编写一个应用程序,而不是使用某些第三方应用程序,该应用程序在调用时将捕获全屏并将其保存在 c:\screenshot\snap000001.png 中
Instead of using some third party app, I'd like to write an app in Ruby that when invoked, will capture the full screen and save it in c:\screenshot\snap000001.png
图形包很容易在那里,但是如何从全屏中捕获一个区域以保存它?
The graphic package is readily there, but how can you capture a region from the full screen so as to save it?
这个程序是通过一些热键来调用的,比如设置它在CTRL-PrtScn按下时运行,或者CTRL-CTRL(左右都控制),或者ALT-ALT.
This program is to be invoked by some hot-key, such as setting it to be running when CTRL-PrtScn is pressed, or CTRL-CTRL (both control on left and right), or ALT-ALT.
推荐答案
我还没试过(我不在 Windows 上).但是您可以使用 Win32::Screenshot.
I haven't tried it (I'm not on windows). But you could use Win32::Screenshot.
环顾四周时,我发现了以下,它使用该库进行屏幕截图
While looking around, I've found the following, which does the screenshot using that library
width, height, bitmap = Win32::Screenshot.desktop
img_lst = ImageList.new
img_lst.from_blob(bitmap)
img_lst.write('public/screen.png')
并且应该将您的屏幕截图写为 png 文件.
And should write your screenshot as a png file.
这篇关于如何在 Windows 上使用 Ruby 捕获屏幕的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!