class Iup::Image
Image made from greyscale values. The colors are defined in a table, and their indices used when defining the image pixel-map.
Example
The following image is built from 3 colors: the pixmap gives their placement in the 11x11 image, and the constructor uses a block to specify the color for each of the 3 values. When displayed, the image presents a red X on a yellow background.
pixmap_x = [ 1,2,3,3,3,3,3,3,3,2,1, 2,1,2,3,3,3,3,3,2,1,2, 3,2,1,2,3,3,3,2,1,2,3, 3,3,2,1,2,3,2,1,2,3,3, 3,3,3,2,1,2,1,2,3,3,3, 3,3,3,3,2,1,2,3,3,3,3, 3,3,3,2,1,2,1,2,3,3,3, 3,3,2,1,2,3,2,1,2,3,3, 3,2,1,2,3,3,3,2,1,2,3, 2,1,2,3,3,3,3,3,2,1,2, 1,2,3,3,3,3,3,3,3,2,1 ] img = Iup::Image.new(11, 11, pixmap_x) do |i| i.color(1, '0 1 0') i.color(2, '255 0 0') i.color(3, '255 255 0') end
Public Class Methods
Source
# File lib/wrapped/image.rb, line 112 def initialize(width, height, pixels) @handle = IupLib.IupImage(width, height, IupLib.pointer_from_chars(pixels)) # run any provided block on instance, to set up further attributes yield self if block_given? end
Constructor creates an image from raw pixels, using 1-value per pixel. If a block is given, the new instance is yielded to it.
-
width- width of image in pixels -
height- height of image in pixels -
pixels- an array of pixel values, each value being a color index
Public Instance Methods
Source
# File lib/wrapped/image.rb, line 126 def color(index, value=nil) IupLib.IupSetAttribute(@handle, index.to_s, value) end
Access color at given index.
-
index- integer of color found in pixel map -
value- ‘r g b’ representation of color