thanks everyone!<span style="font-family: courier new,monospace;"><br><br>import gtk</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
def grayScalePixBuf( pb, copy ):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> arr = pb.get_pixels_array()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if (copy):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> arr = arr.copy()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> for row in arr:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for pxl in row:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> y = 0.3*pxl[0][0]+0.59*pxl[1][0]+0.11*pxl[2][0]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> pxl[0][0] = y
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> pxl[1][0] = y</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
pxl[2][0] = y</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return gtk.gdk.pixbuf_new_from_array(arr, pb.get_colorspace(), pb.get_bits_per_sample())
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">pb = gtk.gdk.pixbuf_new_from_file("cat.jpg")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">pb = grayScalePixBuf(pb, True)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">pb.save( "grayCat.png", "png", {} )
</span><br><br><br><div><span class="gmail_quote">On 11/1/07, <b class="gmail_sendername">Benjamin M. Schwartz</b> <<a href="mailto:bmschwar@fas.harvard.edu">bmschwar@fas.harvard.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>Erik Blankinship wrote:<br>> Anyone know of an easy technique for turning a pixbuf or cairo context<br>> into grayscale?<br><br>I can't tell what you mean. Do you mean to take a snapshot of an existing
<br>pixbuf, convert that snapshot to grayscale, and display the snapshot over the<br>existing pixbuf? If so, the easiest way I know of is<br>gtk.gdk.Pixbuf.get_pixels_array and gtk.gdk.pixbuf_new_from_array [1]. These<br>
methods allow you to do math on the pixels as a Numeric Python array, and then<br>make a new Pixbuf from the resulting array.<br><br>1.<br><a href="http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--get-pixels-array">
http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--get-pixels-array</a><br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG v1.4.7 (GNU/Linux)<br>Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org">
http://enigmail.mozdev.org</a><br><br>iD8DBQFHKmkCUJT6e6HFtqQRAgrjAJ47VHqmT9j7xVAyNzgKXdgDTxQWMQCffJ6k<br>D26RDImuualfzAdlJNaP4k0=<br>=Oc7S<br>-----END PGP SIGNATURE-----<br></blockquote></div><br>