I am trying to draw a simple 256×256 pixel RGBA square using python’s png module.
I’d like to use the png.Writer function and I imagine I’d have to draw it out using the write() method. I have not had any luck however! I don’t have faith in my current code so I’m willing to take suggestions from scratch
I prefer not to use the PIL if possible.
Any suggestions?
I think the format is what may be affecting you, it seems that
pnghas three formats …The alpha being appended to the end of each RGB sequence.
note the
each row in boxed row flat pixel format.heres a quick example that draws a white square.
note that
Writercan also use the other 2 formats which maybe easier to use.Try to use
numpyits much faster and easier when dealing with matrix operations, images can be represented as matrices.good luck.
If you want to print colors then you would need to calculate the RGB values for that color, for example the color red is (255, 0, 0, 255).