简体   繁体   English

有问题将图像文件复制到剪贴板并手动将其粘贴到浏览器中,python

[英]having issue copy image file to clipboard and manually paste it in browser, python

I am trying to copy image file to clipboard, and then I can manually type 'ctrl + v' in window and paste image in broswer such as paste it in email body.我正在尝试将图像文件复制到剪贴板,然后我可以在 window 中手动键入“ctrl + v”并将图像粘贴到浏览器中,例如将其粘贴到 email 正文中。 It seems no error when run the code, but went paste it, my chrome close immediately.运行代码时似乎没有错误,但是粘贴它,我的 chrome 立即关闭。 Here is my code:这是我的代码:

from io import BytesIO
import win32clipboard
from PIL import Image

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

filepath = r'C:\Users\erica\Desktop\Kai\logo - innoID\image.jpg'
image = Image.open(filepath)

output = BytesIO()
image.convert("RGB").save(output, "PNG")
data = output.getvalue()[8:]
output.close()

send_to_clipboard(win32clipboard.CF_DIB, data)

My computer test your code and chrome close immediately too,I guess it should be a picture format problem in memory, maybe you can modify JPG to BMP format, I tested and it's useful, I am not familiar with the underlying memory operation of the code, I hope to help you a little.我的电脑测试你的代码,chrome也立即关闭,我猜应该是memory中的图片格式问题,也许你可以将JPG修改为BMP格式,我测试过,很好用,我不熟悉代码的底层memory操作,希望对你有一点帮助。

    output = BytesIO()
    image.convert("RGB").save(output, "BMP")
    data = output.getvalue()[14:]
    output.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 将字节复制并粘贴到剪贴板 - Copy and paste bytes to clipboard with python Python:在Windows剪贴板中将svg字符串复制为“ image / svg + xml”格式,因此可以将其粘贴为svg图像 - Python: copy svg string to “image/svg+xml” format in windows clipboard, so can paste it as an svg image 如何使用 Python 将文件/图像复制到 Linux 中的剪贴板 - How to copy a file/image to the clipboard in Linux using Python 如何使用 python 或 CL 将文件复制到剪贴板,以便稍后使用 STRG+V 粘贴? - How copy file to clipboard using python or CL to paste it using STRG+V later on? python中如何将文件复制到剪贴板 - How to copy a file to clipboard in python 如何使用 Selenium 和 Python 将图像从浏览器本机菜单复制到剪贴板 - How to Copy image to clipboard from the browser native menu using Selenium and Python Python - matplotlib - PyQT:将图像复制到剪贴板 - Python - matplotlib - PyQT: Copy image to clipboard 使用 Python 将 PIL 图像复制到 macOS 剪贴板 - copy an PIL image to the macOS clipboard with Python 如何在 Python 中从剪贴板复制图像? - How to copy a image from clipboard in Python? 使用 python 将图像复制到 MacOS 剪贴板 - Copy an image to MacOS clipboard using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM