copy image into clipboard

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

filepath = 'D:\\PycharmProjects\\untitled9\\截图.png'.decode('utf-8')

image = Image.open(filepath)
output = StringIO()
image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)

posted @ 2017-03-28 09:50  idlewith  阅读(276)  评论(0编辑  收藏  举报