import pyperclip
pyperclip.copy('北巷的猫') # 只支持字符串类型
# pandas
import pandas as pd
df = pd.read_clipboard()
df
北巷的猫 |
---|
# pyperclip
import pyperclip
text = pyperclip.paste()
text
'北巷的猫'
from PIL import Image, ImageGrab
im = ImageGrab.grabclipboard()
im
# 转化为 bytes 类型
import io
buf = io.BytesIO()
im.save(buf, format='png')
byte_im = buf.getvalue()
len(byte_im)
1850189
file = r'C:\Users\BXDM\Pictures\O1CN01Xg2hFN2D9HRpvXlKH_!!2208169218566.jpg_400x400.jpg'
from PIL import Image
img = open(file, 'rb').read()
print(len(img))
display(Image.open(file))
40114
参考资料
python从粘贴板上读取数据
Python从剪贴板上复制图像到PIL库中
Convert PIL or OpenCV Image to Bytes without Saving to Disk