python - 将 PIL 图像复制到剪贴板(Python)
问题描述
我已经用 Tkinter 在 Python 中制作了一个小画图程序,现在我想添加一个“复制”功能,这样你就可以在 Discord 等其他应用程序中更快地使用 CTRL + V 绘图。这是一个测试:
def Copy():
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
x2 = fen.winfo_rootx()+Can.winfo_x()
y2 = fen.winfo_rooty()+Can.winfo_y()
x1 = x2+Can.winfo_width()
y1 = y2+Can.winfo_height()
print("save")
ImageGrab.grab().crop((x2,y2,x1,y1)).save("Image.bmp")
filepath = "Image.bmp"
image = Image.open(filepath)
output = io.BytesIO()
image.convert("RGB")
image.save(output, "BMP")
data = output.getvalue()[8:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
当我尝试这个时,它可以工作,除了我无法将图像粘贴到 Paint 或 Discord 中......或者它无法读取它,或者它崩溃。有人能帮助我吗?;-;
解决方案
推荐阅读
- ios - 问:在启动屏幕中添加不带@Binding 的关闭按钮
- r - R按组识别数据框更改模式
- javascript - Node.js 常量不等待异步函数的响应
- c - dlsym 导入方法一次供后续使用
- reactjs - 如何在设置 authContext 和登录状态之前等待 cookie。反应,火力基地
- tensorflow - 恢复保存的模型/会话后验证精度差,尽管在训练过程中很好
- protractor - 如何在量角器中转换javascipt
- php - NGINX 和 PHP-FPM (7.4) 在 ubuntu 404 上通过 javascript 访问的 .php 文件
- amazon-web-services - 无法将数组传递给 AWS StepFunction 中的参数
- python - 试图在 tkinter 中打印我的菜单 gui 的总成本。ERROR = 'int' 对象不可调用