将图像保存在 clipboatd 中 - 在 Python/Tkinter 中 [英] save the image in the clipboatd - in Python/Tkinter

查看:28
本文介绍了将图像保存在 clipboatd 中 - 在 Python/Tkinter 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题说明了一切:是否可以将剪贴板中的图像保存到 Tkinter 下的文件中?

the subject says it all: is it possible to take an image present in the clipboard and save it to file under Tkinter?

推荐答案

这是一个脚本,可以让您在 Windows 上获取任意剪贴板数据.

Here is a script that should get let you get arbitrary clipboard data on windows.

import win32clipboard as clip

# The standard windows clipboard formats
formats = ['CF_OEMTEXT', 'CF_PALETTE', 'CF_TEXT', 'CF_ENHMETAFILE', 'CF_UNICODETEXT', 
            'CF_BITMAP', 'CF_METAFILEPICT', 'CF_DIB', 'CF_DIBV5']

def getFromClipboard(format):
    '""Returns a given type of data from the clipboard.'
    data = None
    clip.OpenClipboard(0)
    if clip.IsClipboardFormatAvailable(format):
        data = clip.GetClipboardData(format)
    clip.CloseClipboard()
    return data

good_formats = []
clip.OpenClipboard(0)
for format in formats:
    if clip.IsClipboardFormatAvailable(format):
        good_formats.append(format)
clip.CloseClipboard()

# choose among the good formats here
print good_formats

# use the one you picked here
data = getFromClipboard(good_formats[0])

然后data就是原始图片数据,你就可以正常保存到文件中了.

Then data will be the raw image data and you can just save it to a file normally.

http://msdn.microsoft.com/en-us/library/ms649013%28v=VS.85%29.aspx

http://docs.activestate.com/activepython/2.4/pywin32/win32clipboard__GetClipboardData_meth.html

提供一些信息,更多信息.

Provide some information, more is out there.

这篇关于将图像保存在 clipboatd 中 - 在 Python/Tkinter 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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