Skip to content

Instantly share code, notes, and snippets.

@Karrets
Created July 8, 2021 00:28
Convert image to c(++) formatted array
import numpy
from PIL import Image
image = Image.open("input.png")
arr = numpy.array(image)
output = "{"
for row in arr:
for pixel in row:
for color in pixel:
output += str(color) + ", "
output += "255, "
output += "\n"
output += "}"
text_file = open("out.txt", "w")
text_file.write(output)
text_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment