Copy image to clipboard in Python3

from PIL import Image
from io import BytesIO
import win32clipboard

def send_msg_to_clip(type_data, msg):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(type_data, msg)
    win32clipboard.CloseClipboard()


def paste_img(file_img):
    image = Image.open(file_img)
    output = BytesIO()
    image.convert('RGB').save(output, 'BMP')
    data = output.getvalue()[14:]
    output.close()
    send_msg_to_clip(win32clipboard.CF_DIB, data)


posted @ 2018-04-18 15:48  idlewith  阅读(276)  评论(0编辑  收藏  举报