Converting a PIL image object to a buffer

Gary Herron gherron at islandtraining.com
Wed Apr 1 22:43:58 CEST 2009


Simon Hibbs wrote:
> I'm trying to dump a snapshot of my application window to the
> clipboard. I can use ImageGrab in PIL to get the screen data into a
> PIL image object, which i have converted to a bitmap using ImageWin,
> but when I try to pass this to the clipboard using -
>
> win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)
>
> It fails, telling be that "The object must support the buffer
> interface".
>
> How can I convert a PIL image into a buffer object? I can't find any
> clues.
>   

PIL images have a tostring method that returns a string containing all 
the pixel data.  Would that help you to either create the needed 
buffer?  Or perhaps you could by-pass the need for a buffer, and just 
use the byte string.

Gary Herron

> Help appreciated,
>
> Simon Hibbs
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   




More information about the Python-list mailing list