我收到错误“PIL.UnidentifiedImageError:无法识别位于 0x000001FFA78D10E0> 处的图像文件 <_io.BytesIO 对象””将字节转换为 img 时

发布于 2025-01-14 00:49:24 字数 1051 浏览 6 评论 0 原文

我正在尝试将 2 字节数组合并在一起,并将所有字节转换回图像。但是,我不断收到问题“open raise UnidentifiedImageError(PIL.UnidentifiedImageError:无法识别0x000001FFA78D10E0处的图像文件<_io.BytesIO对象>”

from email.mime import base
import io
import base64
from PIL import Image
from numpy import byte
from array import array


compressedIm = Image.open(r"C:\Users\Student\Documents\Disso\Compressed_gabieureka.jpg")
compressedIm_resize = compressedIm.resize((500, 500))
buf = io.BytesIO()
compressedIm_resize.save(buf, format='JPEG')
byte_compressedIm = buf.getvalue()

Im2 = Image.open(r"C:\Users\Student\Documents\Disso\Photos\votetemi.jpg")
Im2_resize = Im2.resize((500, 500))
buf2 = io.BytesIO()
Im2_resize.save(buf2, format='JPEG')
byte_Im2 = buf2.getvalue()

bytearray1 = bytearray(byte_compressedIm)
bytearray2 = bytearray(byte_Im2)
mergedBytearray = bytearray1 + bytearray2

b = base64.b64decode(mergedBytearray)
image = Image.open(io.BytesIO(b))
image.show()
image.save("TheirDate", "PNG")

有人有解决方案或者可以在我的代码中发现明显的错误吗?

I am attempting to merge 2-byte arrays together and convert the bytes all together back into an image. However, I keep getting the issue "open raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001FFA78D10E0>"

from email.mime import base
import io
import base64
from PIL import Image
from numpy import byte
from array import array


compressedIm = Image.open(r"C:\Users\Student\Documents\Disso\Compressed_gabieureka.jpg")
compressedIm_resize = compressedIm.resize((500, 500))
buf = io.BytesIO()
compressedIm_resize.save(buf, format='JPEG')
byte_compressedIm = buf.getvalue()

Im2 = Image.open(r"C:\Users\Student\Documents\Disso\Photos\votetemi.jpg")
Im2_resize = Im2.resize((500, 500))
buf2 = io.BytesIO()
Im2_resize.save(buf2, format='JPEG')
byte_Im2 = buf2.getvalue()

bytearray1 = bytearray(byte_compressedIm)
bytearray2 = bytearray(byte_Im2)
mergedBytearray = bytearray1 + bytearray2

b = base64.b64decode(mergedBytearray)
image = Image.open(io.BytesIO(b))
image.show()
image.save("TheirDate", "PNG")

Does anyone have a solution or can spot a glaring error in my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文