The result of bytes([0] * 10)
is the string "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"
. So, the colors of your pixels are the ASCII codes of '['
, '0'
, ','
, ' '
, and ']'
symbols.
To get the byte string of zero bytes use bytes("\x00" * 100 * 100)
instead. Here \x00
is the byte with hexadecimal value 00
.
Actually you don't even need bytes(...)
call. bytes
is the type only in Python 3.x. In Python 2.7.x bytes
is just an alias for str
.
So, the final code should be:
from PIL import Image
im = Image.frombytes('L', (100, 100), "\x00" * 100 * 100)
im.show()