Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Capture Screenshots on Windows with Ruby
Ruby
Tag: v0.0.4

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
History.rdoc
LICENSE
README.rdoc
Rakefile
VERSION

README.rdoc

Win32::Screenshot (old name win32screenshot)

DESCRIPTION

Capture Screenshots on Windows with Ruby. This library captures screenshots in bmp format, but you may use RMagick to convert these to some other formats like png.

SYNOPSIS

require 'win32/screenshot'

# take a screenshot of the foreground window
Win32::Screenshot.foreground do |width, height, bmp|
  File.open("picture1.bmp", "wb") {|file| file.puts bmp}
end

# take a screenshot of the screen
Win32::Screenshot.desktop do |width, height, bmp|
  File.open("picture2.bmp", "wb") {|file| file.puts bmp}
end

# take a screenshot of the window, which has a text part of it's title
Win32::Screenshot.window("Internet Explorer") do |width, height, bmp|
  File.open("picture3.bmp", "wb") {|file| file.puts bmp}
end

# take a screenshot of the window, which matches regexp against it's title
Win32::Screenshot.window(/Internet Explorer/) do |width, height, bmp|
  File.open("picture4.bmp", "wb") {|file| file.puts bmp}
end

# take a screenshot of the window with specified window handle
Win32::Screenshot.hwnd(window_handle) do |width, height, bmp|
  File.open("picture5.bmp", "wb") {|file| file.puts bmp}
end

# convert a screenshot to the png format with RMagick
require 'rmagick'

Win32::Screenshot.hwnd(window_handle) do |width, height, bmp|
  img = Magick::Image.from_blob(bmp)
  png = img[0].to_blob {self.format = 'PNG'}
  File.open("picture6.png", "wb") {|file| file.puts png}
end

Copyright

Copyright © 2010 Jarmo Pertman, Aslak Hellesøy. See LICENSE for details.

Something went wrong with that request. Please try again.