Converting a PIL image object to a buffer

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 8 01:52:29 EDT 2009


En Wed, 01 Apr 2009 19:20:43 -0300, Simon Hibbs <simon.hibbs at gmail.com>  
escribió:
> On 1 Apr, 21:43, Gary Herron <gher... at islandtraining.com> wrote:
>> 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".

The second argument to SetClipboardData should be a handle to a bitmap  
resource, not a string.
See win32\test\test_clipboard.py for an example.

PS: Hmm, looking at SetClipboardData, seems that a string containing the  
data in the right format *might* work too. But it's easier to use  
LoadImage than building the resource by hand, I think.

-- 
Gabriel Genellina




More information about the Python-list mailing list