from io import BytesIO
from PIL import Image
with BytesIO() as output:
with Image.open(path_to_image) as img:
img.save(output, 'BMP')
data = output.getvalue()
This method returns the raw image data from the internal
storage. For compressed image data (e.g. PNG, JPEG) use
:meth:~.save, with a BytesIO parameter for in-memory
data.
这是tobytes方法中的警告。因此,我们可以使用带BytesIO参数的save方法来获取压缩字节数组。
相关问题 更多 >
编程相关推荐