# coding=UTF-8
import cairo
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 200, 200)
img = cairo.ImageSurface.create_from_png("sf.png")
ctx = cairo.Context(surface)
ctx.set_source_surface(img, 0, 0)
ctx.paint()
ia = surface.get_data()
for ip in range(0, surface.get_stride() *
surface.get_height(), 4):
if (ip/surface.get_stride())%2 == 0 :
ia[ip+0] = chr(ord(ia[ip+0])/2)
ia[ip+1] = chr(ord(ia[ip+1])/2)
ia[ip+2] = chr(ord(ia[ip+2])/2)
surface.write_to_png('sample1034a.png')
元画像(sf.jpg)
出力画像(sample1034a.png)
動作環境
Python2.6.1, GTK+2.16.0, pycairo1.4.12-2
関連項目
pycairoのまとめ
pycairoをWindowsにインストール
No comments:
Post a Comment