On 1/08/2003 4:46 AM, Anthony Joseph Seward wrote:

On Wed, 2003-07-30 at 11:45, Christian Reis wrote:


On Tue, Jul 29, 2003 at 09:27:45AM +1200, Tim Evans wrote:


Anthony Joseph Seward wrote:



I am trying to figure out a simple way of converting a Numeric array to
a gtk.gdk.Pixbuf without depending on PIL.


[snip]



Assuming that you have a (n,m,3) or (n,m,4) shape 'b' type array of RGB or RGBA values called 'data', you would do this:

w,h = data.shape[:2]
hasalpha = shape.shape[3] == 4
p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, hasalpha, 8, w, h)
p.pixel_array[:] = data


Added as FAQ 8.3, thanks:

http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq08.003.htp

Take care,



The PyGTK reference at http://www.moeraki.com/pygtkreference/pygtk2reference/class-gdkpixbuf.html says Attributes

"pixel_array" Read A numeric ...

So according to the reference pixel_array is a read only attribute. Is
the reference in error?


You can't set the pixel_array attribute, but you can modify the existing value. Note however that modifying the pixel data of some GdkPixbufs will cause a segfault (ones that are backed by a const string, such as the stock icons). Pixbufs you create yourself are safe to modify though.

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/



_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to