當前位置: 首頁>>代碼示例>>Python>>正文


Python Context.get_source方法代碼示例

本文整理匯總了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
開發者ID:moyogo,項目名稱:freetype-py,代碼行數:33,代碼來源:glyph-lcd-cairo.py

示例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()
開發者ID:moyogo,項目名稱:freetype-py,代碼行數:32,代碼來源:wordle-cairo.py

示例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()
開發者ID:moyogo,項目名稱:freetype-py,代碼行數:31,代碼來源:glyph-color-cairo.py


注:本文中的cairo.Context.get_source方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。