Update colour writing to use from_array GitOrigin-RevId: 891ab17e101d369d4ce2e06707ece1139de1eb4b Change-Id: I110a0328e8f061b4ea2dfe18412a63bc24421da2
diff --git a/man/ex.rst b/man/ex.rst index e0d8b04..6aa558e 100644 --- a/man/ex.rst +++ b/man/ex.rst
@@ -106,19 +106,19 @@ Colour ^^^^^^ -For colour images the input rows are generally 3 times as long as -for greyscale, because there are 3 channels, RGB, instead of just -one, grey. Below, the *p* literal has 2 rows of 9 values (3 RGB +For colour images the input rows are like +``[ R, G, B, R, G, B, R, G, B, ... ]``; +a row for *w* pixels will have ``3 * w`` values in it, +because there are 3 channels, RGB. +Below, the *rows* literal has 2 rows of 9 values (3 RGB pixels per row). The spaces are just for your benefit, to mark out the separate pixels; they have no meaning in the code. :: - import png - p = [(255,0,0, 0,255,0, 0,0,255), - (128,0,0, 0,128,0, 0,0,128)] - f = open('swatch.png', 'wb') - w = png.Writer(3, 2, greyscale=False) - w.write(f, p) - f.close() + import png + rows = [(255,0,0, 0,255,0, 0,0,255), + (128,0,0, 0,128,0, 0,0,128)] + image = png.from_array(rows, "RGB") + image.save("swatch.png") More Colour