本文共 1237 字,大约阅读时间需要 4 分钟。
现在实现的功能是ruby的截图模块。主要是通过win32screenshot gem来完成的。
首先是安装:win32screenshot
http://rubygems.org/gems/win32screenshot
gem install win32screenshot
其次就可以来进行测试了。
require 'win32/screenshot'# Take a screenshot of the window with the specified title 用来获取特殊标题的窗口图片,比如说打开某个文件夹。Win32::Screenshot::Take.of(:window, :title => "Windows Internet Explorer").write("image.bmp")# Take a screenshot of the foreground 用来获取当前窗口的图片Win32::Screenshot::Take.of(:foreground).write("image.png")# Take a screenshot of the specified window's top-left corner's area 获取特定区域的图片Win32::Screenshot::Take.of(:window, :title => /internet/i, :area => [10, 10, 20, 20]).write("image.jpg")# Take a screenshot of the window with the specified handle Win32::Screenshot::Take.of(:window, :hwnd => 123456).write("image.gif")# Take a screenshot of the child window with the specified internal class name 可以获取子对象的图片Win32::Screenshot::Take.of(:rautomation, RAutomation::Window.new(:hwnd => 123456). child(:class => "Internet Explorer_Server")).write("image.png")# Use the bitmap blob for something elseimage = Win32::Screenshot::Take.of(:window, :hwnd => 123456)image.height # => height of the imageimage.width # => width of the imageimage.bitmap # => bitmap blob
转载地址:http://jgcci.baihongyu.com/