class Shortcut::Screen
Public Class Methods
new(opts = {})
click to toggle source
# File lib/shortcut/screen.rb, line 10 def initialize(opts = {}) dim = Toolkit.get_default_toolkit.get_screen_size opts = {:x => 0, :y => 0, :width => dim.get_width, :height => dim.get_height}.merge(opts) rectangle = Rectangle.new(opts[:x], opts[:y], opts[:width], opts[:height]) @robot = Robot.new @image = @robot.create_screen_capture(rectangle) end
Public Instance Methods
find_template(template)
click to toggle source
# File lib/shortcut/screen.rb, line 33 def find_template(template) for x in 0...(@image.getWidth - template.getWidth) for y in 0...(@image.getHeight - template.getHeight) if loop_through_template(template, x, y) return Point.new(x, y) end end end return false end
get_color(x, y)
click to toggle source
# File lib/shortcut/screen.rb, line 24 def get_color(x, y) @image.getRGB(x, y) end
get_color_hex(x, y)
click to toggle source
# File lib/shortcut/screen.rb, line 28 def get_color_hex(x, y) color = get_color(x, y) sprintf("%02X%02X%02X", (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF) end
save_image(pathname)
click to toggle source
# File lib/shortcut/screen.rb, line 19 def save_image(pathname) file = java::io::File.new(pathname) ImageIO.write(@image, "PNG", file) end
Private Instance Methods
loop_through_template(template, x, y)
click to toggle source
# File lib/shortcut/screen.rb, line 47 def loop_through_template(template, x, y) for i in 0...template.getWidth for j in 0...template.getHeight return false if get_color(x+i, y+j) - template.getRGB(i, j) != 0 end end return true end