我有this image大小为 128 x 128 像素,RGBA 作为字节值存储在我的内存中。但是
from PIL import Image
image_data = ... # byte values of the image
image = Image.frombytes('RGBA', (128,128), image_data)
image.show()
抛出异常
ValueError: not enough image data
为什么?我做错了什么?
最佳答案
The documentation for Image.open
说它可以接受类似文件的对象,因此您应该能够传入从包含编码图像的 bytes
对象创建的 io.BytesIO
对象:
from PIL import Image
import io
image_data = ... # byte values of the image
image = Image.open(io.BytesIO(image_data))
image.show()
关于python - 从字节文件打开 PIL 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46884404/