The creation of a bitmap can be performed out of some unpacked binary data by first creating image instances:
from pyx import *
image_bw = bitmap.image(2, 2, "L", "\0\377\377\0")
image_rgb = bitmap.image(3, 2, "RGB", "\77\77\77\177\177\177\277\277\277"
"\377\0\0\0\377\0\0\0\377")
image_bw is a "\0" ==
chr(0)) and two white ("\377" == chr(255)) pixels. Currently
the values per (colour) channel is fixed to 8 bits. The coloured image
image_rgb has
The images can then be wrapped into bitmap instances by:
bitmap_bw = bitmap.bitmap(0, 1, image_bw, height=0.8) bitmap_rgb = bitmap.bitmap(0, 0, image_rgb, height=0.8)
bitmap instance you have to specify a
certain position by the first two arguments fixing the bitmaps lower
left corner. Some optional arguments control further properties. Since
in this example there is no information about the dpi-value of the
images, we have to specify at least a width or a height
of the bitmap.
The bitmaps are now to be inserted into a canvas:
c = canvas.canvas()
c.insert(bitmap_bw)
c.insert(bitmap_rgb)
c.writeEPSfile("bitmap")
![]() |