Re: Example Code for Displaying Pictures--I'm Stumped

Bill Janssen <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
Another good option is pyglet.  I use it for converting video to streams
of PIL images.

Here's the code for turning a pyglet image into a PIL image:

    def pyglet_to_pil_image (pyglet_image):
        image = pyglet_image.get_image_data()
        format = image.format
        if format != 'RGB':
            # Only save in RGB or RGBA formats.
            format = 'RGBA'
        pitch = -(image.width * len(format))

        # Note: Don't try and use frombuffer(..); different versions of
        # PIL will orient the image differently.
        pil_image = Image.fromstring(
            format, (image.width, image.height), image.get_data(format, pitch))
        # need to flip the image to accommodate Pyglet's transform space
        pil_image = pil_image.transpose(Image.FLIP_TOP_BOTTOM)
        return pil_image

This code is part of extensions/video.py, part of the UpLib source code
at http://uplib.parc.com/.

Bill
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.