PyGTK and draw_array
Iain Calder
iain at wombatzone.freeserve.co.uk
Sun Jul 2 17:29:16 EDT 2000
Esko Lehtonen wrote:
>
> I am trying to manipulate an image and then draw it to GtkDrawingArea
> using PyGtk and Numerical Python.
<snip>
> So I made following code:
>
> WIDTH = 30
> HEIGHT = 20
> D = 3
> # create rgb image as array, every value 100
> img = ones((WIDTH, HEIGHT, D), 'b')
> img = img * 100
> ----
> darea = GtkDrawingArea()
> ----
> draw_array(darea.get_window(),
> widget.get_style().black_gc, x, y,
> GDK.RGB_DITHER_NORMAL, img)
>
> I still have a problem, because then a got: "TypeError: array data must
> be unsigned bytes" when I'm trying to use the draw_array function.
After multiplying by 100, img is not longer of type 'b'. img.typecode()
returns 'i'.
Use img=img.astype('b') before the call to draw_array to cast back to
bytes.
HTH,
Iain Calder
More information about the Python-list
mailing list