# 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):
maxv = max(ord(ia[ip+0]), ord(ia[ip+1]), ord(ia[ip+2]))
minv = max(ord(ia[ip+0]), ord(ia[ip+1]), ord(ia[ip+2]))
pval = (maxv+minv)/2
ia[ip+0] = chr(int(pval * 0x55/float(0xff)))
ia[ip+1] = chr(int(pval * 0xaa/float(0xff)))
ia[ip+2] = chr(int(pval * 0xee/float(0xff)))
surface.write_to_png('sample1033a.png')
元画像(sf.png)
出力画像(sample1033a.png)
動作環境
Python2.6.1, GTK+2.16.0, pycairo1.4.12-2
関連項目
pycairoのまとめ
pycairoをWindowsにインストール
No comments:
Post a Comment