在python中将文件存储在剪贴板中 [英] Storing a file in the clipboard in python

查看:480
本文介绍了在python中将文件存储在剪贴板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用win32clipboard模块在python的Windows剪贴板中存储对文件的引用。我的目标是以允许透明的方式粘贴图像。如果我将 png文件拖放到OneNote中,或者复制该文件然后将其粘贴到OneNote中,这似乎可以保持透明度。据我所知,剪贴板无法存储透明图像,这就是为什么它必须是对文件的引用。

Is there a way to use the win32clipboard module to store a reference to a file in the windows clipboard in python. My goal is to paste an image in a way that allows transparency. If I drag and drop a 'png' file into OneNote or I copy the file and then paste it into OneNote, this seems to preserve transparency. As far as I can tell, the clipboard can't store transparent images which is why it has to be a reference to a file.

我的研究表明,它可能涉及win32clipboard.CF_HDrop属性,但我不确定。

My research suggests that it might involve the win32clipboard.CF_HDrop attribute but I'm not sure.

所以,总结一下,我的目标是要有一些我可以单击并使用的python代码例如,我桌面上的一个名为 img.png的特定文件。结果是 img.png存储在剪贴板中,并可以粘贴到其他程序中。本质上,与我自己在桌面上选择文件,右键单击并选择复制的行为相同。

So, just to summarize, my goal is to have a bit of python code which I can click and which uses a specific file on my Desktop named 'img.png' for instance. The result is that 'img.png' gets stored in the clipboard and can be pasted into other programs. Essentially, the same behavior as if I selected the file on the Desktop myself, right-clicked and selected 'Copy'.

编辑:
此页面似乎建议以某种方式使用win32clipboard.CF_HDrop:
http:// timgolden。 me.uk/pywin32-docs/win32clipboard__GetClipboardData_meth.html

它说 CF_HDROP与一堆Unicode文件名相关联

It says "CF_HDROP" is associated with "a tuple of Unicode filenames"

推荐答案

from PythonMagick import Image
Image("img.png").write("clipboard:") 

获取 Windows二进制文件 for PythonMagick

Grab the windows binaries for PythonMagick

这篇关于在python中将文件存储在剪贴板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆