How to copy a picture from canvas to clipboard?

流过昼夜 提交于 2019-12-19 04:04:18

问题


I have some Tkinter canvas and some picture of lines and text on it. Is there an easy way to copy it to a clipboard?


回答1:


You could use .postscript method of the canvas to get an Encapsulated PostScript (EPS) representation of the contents. Then, use `ImageMagick's Python bindings (PythonMagick or PythonMagickWand) to convert the EPS to a Windows Enhanced Metafile (EMF). Finally, copy it to the clipboard (e.g. using nosklo's solution) with the CF_ENHMETAFILE clipboard format.




回答2:


To use windows clipboard you must convert the image data to a format accepted by win api. Then, just use this function:

import win32clipboard

def send_to_clibboard(clip_type, data): 
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(clip_type, data) 
    win32clipboard.CloseClipboard()

Where clip_type can be win32clipboard.CF_BITMAP, win32clipboard.CF_TIFF or many others.



来源:https://stackoverflow.com/questions/457514/how-to-copy-a-picture-from-canvas-to-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!