Open PIL image from byte file

后端 未结 2 2096
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 02:31

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 im         


        
2条回答
  •  一生所求
    2020-11-29 02:50

    The documentation for Image.open says that it can accept a file-like object, so you should be able to pass in a io.BytesIO object created from the bytes object containing the encoded image:

    from PIL import Image
    import io
    
    image_data = ... # byte values of the image
    image = Image.open(io.BytesIO(image_data))
    image.show()
    

提交回复
热议问题