本文整理汇总了Python中cairo.Context.mask方法的典型用法代码示例。如果您正苦于以下问题:Python Context.mask方法的具体用法?Python Context.mask怎么用?Python Context.mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.mask方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Matrix
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import mask [as 别名]
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()
# stroke on top
ctx.set_source_surface(Z, 0, 0)
patternZ = ctx.get_source()
SurfacePattern.set_filter(patternZ, FILTER_BEST)
scalematrix = Matrix()
scalematrix.scale(1.0/scale,1.0/scale)
scalematrix.translate(-(600.0 - widthZ *scale /2.0 ), -50)
示例2: spiral
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import mask [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: make_image_surface
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import mask [as 别名]
FT_LOAD_TARGET_MONO )
bitmap = face.glyph.bitmap
width = face.glyph.bitmap.width
rows = face.glyph.bitmap.rows
pitch = face.glyph.bitmap.pitch
glyph_surface = make_image_surface(face.glyph.bitmap)
surface = ImageSurface(FORMAT_ARGB32, 800, 600)
ctx = Context(surface)
ctx.rectangle(0,0,800,600)
ctx.set_line_width(0)
ctx.set_source_rgb (0.5 , 0.5, 0.5)
ctx.fill()
#
scale = 480.0 / rows
ctx.set_source_surface(glyph_surface, 0, 0)
pattern = ctx.get_source()
SurfacePattern.set_filter(pattern, FILTER_BEST)
scalematrix = Matrix()
scalematrix.scale(1.0/scale,1.0/scale)
scalematrix.translate(-(400.0 - width *scale /2.0 ), -60)
pattern.set_matrix(scalematrix)
ctx.set_source_rgb (0 , 0, 1)
ctx.mask(pattern)
ctx.fill()
surface.flush()
surface.write_to_png("glyph-mono+alpha-cairo.png")
Image.open("glyph-mono+alpha-cairo.png").show()