PyX — Example: bitmap/minimal.py
Store bitmap data using PyX
from pyx import * image_bw = bitmap.image(2, 2, "L", b"\0\377\377\0") image_rgb = bitmap.image(3, 2, "RGB", b"\77\77\77\177\177\177\277\277\277" b"\377\0\0\0\377\0\0\0\377") bitmap_bw = bitmap.bitmap(0, 1, image_bw, height=0.8) bitmap_rgb = bitmap.bitmap(0, 0, image_rgb, height=0.8) c = canvas.canvas() c.insert(bitmap_bw) c.insert(bitmap_rgb) c.writeEPSfile("minimal") c.writePDFfile("minimal") c.writeSVGfile("minimal")
While the main purpose of PyX is to create vector graphics, it is also possible to store bitmap data in the PyX output. In this example, we show how to create a simple data structure containing the bitmap data and how such data can then be transformed into an object which can be inserted into a PyX canvas.
The first step of providing the bitmap data is creating an
image instance. You need to specify the size of your data (in pixels) followed by strings describing the type of the bitmap and the bitmap data itself.
The bitmap functionality currently uses a fixed color depth of 8 bits per color. The pixels are listed row by row, one after the other starting at the upper left corner of the image.
Once the image data has been prepared, a
bitmap instance can be created and inserted into a PyX canvas for later output.