0

I am confronted to the loss of alpha channel when I try to send image to clipboard, none of the solutions described here worked with the software I am working with but when I copy paste png files into this software, the alpha channel seems to be preserved. Under this consideration, I want to simulate the Ctrl+C on files allowed by Windows Explorer. Using Clipview I found that the field 15 : CF_HDROP is relevant to my goal. tried to set this field using win32clipboard

import win32clipboard
win32clipboard.OpenClipboard(0)
file1="C:\\Users\\User\\Desktop\\test.png"
win32clipboard.SetClipboardData(15, file1)
win32clipboard.CloseClipboard()

I don't get any error doing this, but it does not work when I try to use this new clipboard content, because as described there tuple of unicode filenames must be stored in the CF_HDROP field.

I have no clue how to proceed. I also tried with file1= (unicode('C:\\Users\\User\\Desktop\\CANEVAS\\test.png'),) but I got this error:

TypeError: expected a readable buffer object.

4

1 回答 1

0

CF_HDROP的文档说

数据由包含全局内存对象的STGMEDIUM结构组成。该结构的 hGlobal 成员指向一个DROPFILES结构作为其 hGlobal 成员。

win32clipboard.GetClipboardData 内置了对 CF_HDROP 的支持。它解码 STGMEDIUM 和 DROPFILES 结构以生成文件名元组。

该文档没有说明 SetClipboardData 具有从文件名元组构造 STGMEDIUM 和 DROPFILES 结构的相应代码。

我对 Python 或其 FFI 了解不多,无法知道构造结构并将它们传递给 SetClipboardData 函数是多么简单。或者,如果有一个现有的图书馆可以为你做这件事。

于 2013-10-30T00:27:45.613 回答