How to capture a part of a screen using Ruby on Windows?
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?
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.
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')
And should write your screenshot as a png file.
精彩评论