I am trying to convert raw data of length 64372(w= 242, h=266) to the image, the raw data is in the format of the byte array, I want to convert this byte array into image, can you help me with that?
解决方案
You can generate a bytearray of dummy data representing a gradient like this:
import numpy as np
# Generate a left-right gradient 242 px wide by 266 pixels tall
ba = bytearray((np.arange(242) + np.zeros((266,1))).astype(np.uint8))
For reference, that array will contain data like this:
array([[ 0., 1., 2., ..., 239., 240., 241.],
[ 0., 1., 2., ..., 239., 240., 241.],
[ 0., 1., 2., ..., 239., 240., 241.],
...,
[ 0., 1., 2., ..., 239., 240., 241.],
[ 0., 1., 2., ..., 239., 240., 241.],
[ 0., 1., 2., ..., 239., 240., 241.]])
And then make into a PIL/Pillow image like thi