Class: Iup::Image
- Inherits:
-
ImageWidget
- Object
- Widget
- ImageWidget
- Iup::Image
- Defined in:
- lib/wrapped/image.rb
Overview
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
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#color(index, value = nil) ⇒ Object
:call-seq: image.color(index) # retrieves image.color(index, value) # sets .
-
#initialize(width, height, pixels) {|_self| ... } ⇒ Image
constructor
Constructor creates an image from raw pixels, using 1-value per pixel.
Methods inherited from ImageWidget
#assign_handle, #bpp, #channels, #height, #hotspot, #rastersize, #save, #wid, #width
Methods inherited from Widget
#active, #assign_handle, #bgcolor, #destroy, #enterwindow_cb=, #fgcolor, #font, #getfocus_cb=, #help_cb=, #k_any=, #killfocus_cb=, #leavewindow_cb=, #map_cb=, #maxsize, #minsize, #open_controls, #size, #unmap_cb=, #visible, #wid, #zorder
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_reader, #define_id_writer, #define_property_attribute, #define_property_reader, #define_property_writer, #define_reader, #define_writer
Methods included from CallbackSetter
Constructor Details
#initialize(width, height, pixels) {|_self| ... } ⇒ Image
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
112 113 114 115 116 117 |
# 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 |
Instance Method Details
#color(index, value = nil) ⇒ Object
:call-seq:
image.color(index) # retrieves
image.color(index, value) # sets
Access color at given index.
-
index- integer of color found in pixel map -
value- ‘r g b’ representation of color
126 127 128 |
# File 'lib/wrapped/image.rb', line 126 def color(index, value=nil) IupLib.IupSetAttribute(@handle, index.to_s, value) end |