本文整理汇总了Python中cairo.Context.get_source方法的典型用法代码示例。如果您正苦于以下问题:Python Context.get_source方法的具体用法?Python Context.get_source怎么用?Python Context.get_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.get_source方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ndarray
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_source [as 别名]
strides=[pitch, 3])
try:
ndI = ndarray(shape=(rows,width), buffer=I.get_data(),
dtype=uint32, order='C',
strides=[I.get_stride(), 4])
except NotImplementedError:
raise SystemExit("For python 3.x, you need pycairo >= 1.11+ (from https://github.com/pygobject/pycairo)")
# 255 * 2**24 = opaque
ndI[:,:] = 255 * 2**24 + ndR[:,:] * 2**16 + ndG[:,:] * 2**8 + ndB[:,:]
I.mark_dirty()
surface = ImageSurface(FORMAT_ARGB32, 800, 600)
ctx = Context(surface)
ctx.set_source_surface(I, 0, 0)
pattern = ctx.get_source()
SurfacePattern.set_filter(pattern, FILTER_BEST)
scale = 480.0 / rows
scalematrix = Matrix()
scalematrix.scale(1.0/scale,1.0/scale)
scalematrix.translate(-(400.0 - width *scale /2.0 )+200, -60)
pattern.set_matrix(scalematrix)
ctx.paint()
# we need this later for shifting the taller LCD_V glyph up.
rows_old = rows
# LCD_V
face.load_char('S', FT_LOAD_RENDER |
FT_LOAD_TARGET_LCD_V )
bitmap = face.glyph.bitmap
示例2: spiral
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_source [as 别名]
y0 = H//2 + (random.uniform()-.1)*50
for dx,dy in spiral():
c = .25+.75*random.random()
x = int(x0+dx)
y = int(y0+dy)
checked = False
I.flush()
if not (x <= w//2 or y <= h//2 or x >= (W-w//2) or y >= (H-h//2)):
ndI = ndarray(shape=(h,w), buffer=I.get_data(), dtype=ubyte, order='C',
offset=(x-w//2) + I.get_stride() * (y-h//2),
strides=[I.get_stride(), 1])
ndL = ndarray(shape=(h,w), buffer=L.get_data(), dtype=ubyte, order='C',
strides=[L.get_stride(), 1])
if ((ndI * ndL).sum() == 0):
checked = True
new_region = RectangleInt(x-w//2, y-h//2, w, h)
if (checked or ( drawn_regions.contains_rectangle(new_region) == REGION_OVERLAP_OUT )):
ctxI.set_source_surface(L, 0, 0)
pattern = ctxI.get_source()
scalematrix = Matrix()
scalematrix.scale(1.0,1.0)
scalematrix.translate(w//2 - x, h//2 - y)
pattern.set_matrix(scalematrix)
ctxI.set_source_rgba(c,c,c,c)
ctxI.mask(pattern)
drawn_regions.union(new_region)
break
I.flush()
I.write_to_png("wordle-cairo.png")
Image.open("wordle-cairo.png").show()
示例3: ImageSurface
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import get_source [as 别名]
# Draw
surface = ImageSurface(FORMAT_ARGB32, 1200, 500)
ctx = Context(surface)
# fill background as gray
ctx.rectangle(0,0,1200,500)
ctx.set_source_rgb (0.5 , 0.5, 0.5)
ctx.fill()
# use the stroked font's size as scale, as it is likely slightly larger
scale = 400.0 / rowsZ
# draw bitmap first
ctx.set_source_surface(F, 0, 0)
patternF = ctx.get_source()
SurfacePattern.set_filter(patternF, FILTER_BEST)
scalematrix = Matrix()
scalematrix.scale(1.0/scale,1.0/scale)
scalematrix.translate(-(600.0 - widthF *scale /2.0 ), -50)
patternF.set_matrix(scalematrix)
ctx.set_source_rgb (1 , 1, 0)
ctx.mask(patternF)
ctx.fill()
scalematrix.translate(+400,0)
patternF.set_matrix(scalematrix)
ctx.mask(patternF)
ctx.fill()