Class: Ev3dev::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/ev3dev/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Image

Returns a new instance of Image.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ev3dev/image.rb', line 8

def initialize(*args)
  require 'RMagick'

  case args.size
  when 0
    @image = Magick::Image.new(192, 128){ self.format = 'mono'}
  when 1
    image_file = args.first

    if image_file.end_with?('.mono')
      @image = Magick::Image.read(image_file){ self.size = "192x128" }.first
    else
      @image = Magick::Image.read(image_file).first
      @image.format = 'mono'
      @image.resize_to_fill!(192, 128)
    end
  else
    raise "ArgumentError: wrong number of arguments 0 or 1"
  end
end

Instance Method Details

#save(output_file) ⇒ Object

resize EV3 Screen(192 x 128) and .mono image format output file name should be ‘.mono’



31
32
33
34
# File 'lib/ev3dev/image.rb', line 31

def save(output_file)
  @image.write(output_file)
  @image.destroy!
end

#text(x, y, size, string) ⇒ Object



36
37
38
39
# File 'lib/ev3dev/image.rb', line 36

def text(x, y, size, string)
  draw = Magick::Draw.new
  draw.annotate(@image, 0, 0, x, y, string){self.pointsize = size}
end