+ 3

Hello everybody, I am trying to make a python code that converts binary information (list of 0,1)into a black and white picture?

It would take a list and return a picture with dimensions that would be put by the user. I tried to make an empty matrix with zeros, but I don't know how to put the binary into the matrix to complete it pixel per pixel until the matrix is complete with the list. Could anyone help me doing this '? I don't know how to start... 😕😕 After that I am wondering how to make the same experiment but the return would be a colored picture 🖼. Thank you for your help. Ps: I am working with python 3+ versions

19th Mar 2019, 1:15 PM
Maximilien
Maximilien  - avatar
2 Réponses
+ 3
check something like : from PIL import Image import struct size = 5, 5 arr = [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0] data = struct.pack('B'*len(arr), *[pixel*255 for pixel in arr]) img = Image.frombuffer('L', size, data) img.save('image.png')
19th Mar 2019, 2:50 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 2
Hello Poulimenos, thanks for your reply, I will try to test and understand your reply because you use some functions I I don't know like struct . 😊
19th Mar 2019, 3:18 PM
Maximilien
Maximilien  - avatar