如何在不使用python文件的情况下将字节数组转换为图像?
#image to bytearray
with open("C:/Downloads/myimage.jpeg", "rb") as image:
f = image.read()
b = bytearray(f)
#bytearray to image
f = open('xyz.jpeg', 'wb')
f.write(bytearray(b))
f.close()
答案 0 :(得分:0)
您可以使用Pillow。首先安装它:pip install Pillow
import io
from PIL import Image
#image to bytearray
with open("C:/Downloads/myimage.jpeg", "rb") as image:
f = image.read()
b = bytearray(f)
image = Image.open(io.BytesIO(b))
image.show()
# image.save("C:/Downloads/myimage_new.jpeg", "JPEG") # to save the image