从字节文件打开PIL图像 [英] Open PIL image from byte file
本文介绍了从字节文件打开PIL图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此图像,其大小为128 x 128像素,RGBA存储为字节值在我的记忆中.但是
I have this image with size 128 x 128 pixels and RGBA stored as byte values in my memory. But
from PIL import Image
image_data = ... # byte values of the image
image = Image.frombytes('RGBA', (128,128), image_data)
image.show()
引发异常
ValueError:图片数据不足
ValueError: not enough image data
为什么?我在做什么错了?
Why? What am I doing wrong?
推荐答案
您可以尝试以下操作:
image = Image.frombytes('RGBA', (128,128), image_data, 'raw')
源代码:
def frombytes(mode, size, data, decoder_name="raw", *args):
param mode: The image mode.
param size: The image size.
param data: A byte buffer containing raw data for the given mode.
param decoder_name: What decoder to use.
这篇关于从字节文件打开PIL图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文