diff options
Diffstat (limited to 'test/isurface_create_for_data2.py')
-rwxr-xr-x | test/isurface_create_for_data2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/isurface_create_for_data2.py b/test/isurface_create_for_data2.py new file mode 100755 index 0000000..88b4c5c --- /dev/null +++ b/test/isurface_create_for_data2.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +"""test cairo.ImageSurface.create_for_data() with a numpy array +""" + +import cairo + +import numpy + +dir_ = "/tmp/" +width, height = 255, 255 +data = numpy.ndarray (shape=(height,width,4), dtype=numpy.uint8) + +for x in range(width): + for y in range(height): + alpha = y + + # cairo.FORMAT_ARGB32 uses pre-multiplied alpha + data[y][x][0] = int(x * alpha/255.0) + data[y][x][1] = int(y * alpha/255.0) + data[y][x][2] = 0 + data[y][x][3] = alpha + +surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32, + width, height) +ctx = cairo.Context(surface) +surface.write_to_png(dir_ + 'for_data2.png') |