0

I have a bytearray as well as image height and width which holds the RGBA BMP image data. I would like to save it to a file.

I tried with PIL image library but with no lock.

stream = BytesIO(b_array)
Image.open(stream)
image = Image.open(stream)
stream.close()
image.save("test.bmp")

The error received

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001E522690D10>

Any help here?

BTW, I don't need BMP, any popular image file format works with me.

biluochun2010
  • 109
  • 1
  • 7

1 Answers1

1
im = Image.new("RGBA", (width, height))
im.frombytes(source)
im.save("test.bmp")
biluochun2010
  • 109
  • 1
  • 7