image create photo" command
to produce a photo image from a NAO.
One can also use the photo image write operation to produce
a NAO from a photo image.
The data type of the NAO is normally
u8 (8-bit unsigned integer).
Any other type will be converted to
u8.
The rank can be 2 or 3. A matrix gives a grey-scale image. Colour requires three dimensions. In this case there normally are three layers corresponding to red, green and blue. If there are only two layers then the first is used for both red and green (which together give yellow).
The name of the new photo image format is "NAO".
The following example (input only shown) creates and displays a grey-scale photo image from a
u8
matrix:
nap "u = u8(reshape(0 .. 255, 2 # 255))" set i [image create photo -format NAO -data $u] button .b -image $i pack .b
The following example (input only shown) creates and displays a colour photo image from a
three-dimensional u8
array.
It then writes this image to a GIF file named "n.gif".
destroy .b
nap "u = u8(reshape({32768#0 65536#255}, {3 2#256}))"
set i [image create photo -format NAO -data $u]
button .b -image $i
pack .b
$i write n.gif -format GIF
The following example (input and output shown) first creates a photo image by reading this
GIF file named "n.gif".
Then a new NAO is created and assigned the name "abc".
% set pi [image create photo -file n.gif] image8 % $pi write abc -format NAO % $abc header ::NAP::2790-2790 u8 MissingValue: (NULL) References: 1 Unit: (NULL) Dimension 0 Size: 3 Name: (NULL) Coordinate-variable: (NULL) Dimension 1 Size: 256 Name: (NULL) Coordinate-variable: (NULL) Dimension 2 Size: 256 Name: (NULL) Coordinate-variable: (NULL)