Ionutz Borcoman wrote:
Hi,
What is the fastest way to display a PIL image in a DrawingArea ?
This will work with RGB and RGBA images:
import PIL.Image, Numeric, gtk
i = PIL.Image.open('foo.png') w, h = i.size data = Numeric.fromstring(i.tostring(), 'b') data.shape = (w, h, -1) p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, i.mode == 'RGBA', 8, w, h) p.pixel_array[:] = data
I use this:
im = Image.open("foo.png")
width, height = im.size
buff = im.tostring()
...
window.draw_rgb_image(gc, x, y, width, height,
gtk.gdk.RGB_DITHER_NONE, buff)I used to do something more convoluted till discovered that this simple code actually works :)
What I woul like to know now is how can I find out how much memory is needed to store the buffer and how much for the image object (aks, should I store in my cache the image objects or the buffer - storing the buff string would require one call less - no more need to call tostring() every time I want to display the image)
A usual, any thoughts and comments are highly appreciated :)
Ionutz
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
