需要安装pywin32,pillow 依赖包
#coding:utf-8
import win32clipboard as clip
import win32con
from PIL import Image
from cStringIO import StringIO
'''
往剪贴板中放入图片
'''
def setImage(data):
clip.OpenClipboard() #打开剪贴板
clip.EmptyClipboard() #先清空剪贴板
clip.SetClipboardData(win32con.CF_DIB, data) #将图片放入剪贴板
clip.CloseClipboard()
if __name__ == '__main__':
imagepath = 'E:\aa.jpg'
img = Image.open(imagepath)
output = StringIO()
img.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()
setImage(data)