Python Script to convert Image into Byte array

前端 未结 4 592
予麋鹿
予麋鹿 2020-12-08 06:36

I am writing a Python script where I want to do bulk photo upload. I want to read an Image and convert it into a byte array. Any suggestions would be greatly appreciated.

4条回答
  •  悲哀的现实
    2020-12-08 06:56

    Use bytearray:

    with open("img.png", "rb") as image:
      f = image.read()
      b = bytearray(f)
      print b[0]
    

    You can also have a look at struct which can do many conversions of that kind.

提交回复
热议问题