[cairo-commit] pycairo/test surface_to_rgba.py,NONE,1.1

Steve Chaplin commit at pdx.freedesktop.org
Mon Jun 26 06:58:24 PDT 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/test
In directory kemper:/tmp/cvs-serv30714/test

Added Files:
	surface_to_rgba.py 
Log Message:
'SC'

--- NEW FILE: surface_to_rgba.py ---
#!/usr/bin/env python
"""
Test surface.to_rgba() - read a pycairo surface into a PIL image.
"""

import Image
import cairo

filename_base = "/tmp/file"

def test_to_rgba (surface, filename):
    width, height = surface.get_width(), surface.get_height()
    data = surface.to_rgba()
    im = Image.frombuffer ("RGBA", (width, height), data, "raw", "RGBA", 0,1)
    im.save (filename)

# 1 ImageSurface
width, height = 150, 100
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context (surface)
ctx.scale (width, height)

pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
pat.add_color_stop_rgba (1, 0, 0, 0, 1)
pat.add_color_stop_rgba (0, 1, 1, 1, 1)

ctx.rectangle (0,0,1,1)
ctx.set_source (pat)
ctx.fill ()

test_to_rgba (surface, filename_base + '.out1.png')

# 2 ImageSurface.create_from_png()
surface = cairo.ImageSurface.create_from_png ('/tmp/arc.png')
test_to_rgba (surface, filename_base + '.out2.png')



More information about the cairo-commit mailing list