Class: Screenshot

Inherits:
Object
  • Object
show all
Includes:
Java
Defined in:
lib/deskshot/screenshot.rb

Class Method Summary collapse

Class Method Details

.captureObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/deskshot/screenshot.rb', line 10

def self.capture
  begin
    output            = FileDialog.new(nil, "Save as", FileDialog::SAVE)
    defaultfilename = Time.now.strftime("%F %H-%M-%S")
    output.setFile(defaultfilename + ".png")
    output.show
    filename          = output.getDirectory + output.getFile
    #to avoide conflict of capturing own menu/window itself
    sleep 1

    robot       = Robot.new
    toolkit      = Toolkit.get_default_toolkit
    dim          = toolkit.get_screen_size
    rectangle  = Rectangle.new(0, 0, dim.get_width, dim.get_height)
    image       = robot.create_screen_capture(rectangle)
    file           = java::io::File.new(filename)
    ImageIO::write(image, "png", file)
  rescue Exception
  end
end