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


Python cairocffi.ImageSurface方法代碼示例

本文整理匯總了Python中cairocffi.ImageSurface方法的典型用法代碼示例。如果您正苦於以下問題:Python cairocffi.ImageSurface方法的具體用法?Python cairocffi.ImageSurface怎麽用?Python cairocffi.ImageSurface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cairocffi的用法示例。


在下文中一共展示了cairocffi.ImageSurface方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_image

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def draw_image(self, gc, x, y, im):
        # bbox - not currently used
        if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))

        im.flipud_out()

        rows, cols, buf = im.color_conv (BYTE_FORMAT)
        surface = cairo.ImageSurface.create_for_data (
                      buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
        ctx = gc.ctx
        y = self.height - y - rows

        ctx.save()
        ctx.set_source_surface (surface, x, y)
        if gc.get_alpha() != 1.0:
            ctx.paint_with_alpha(gc.get_alpha())
        else:
            ctx.paint()
        ctx.restore()

        im.flipud_out() 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:23,代碼來源:backend_cairo.py

示例2: generate_image_temporal

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def generate_image_temporal(x_norm, x_diff_encoded, scale, stroke_width,
    steepness=2, inversed=False):
  surface = cairo.ImageSurface(cairo.FORMAT_A8, scale, scale)

  curr_x = x_norm[0][0]
  curr_y = x_norm[0][1]
  spent_t = 0

  for i, diff in enumerate(x_diff_encoded):
      ctx = cairo.Context(surface)
      ctx.move_to(curr_x * scale, curr_y * scale)
      ctx.set_line_width(stroke_width)
      weight = 1 - spent_t / x_norm[-1][2]
      if inversed: weight = 1 - weight
      weight = max(weight, 0) ** steepness
      if diff[3] == 0: weight /= 2
      ctx.set_source_rgba(1, 1, 1, weight)
      ctx.line_to((curr_x + diff[0]) * scale, (curr_y + diff[1]) * scale)
      ctx.stroke()

      curr_x += diff[0]
      curr_y += diff[1]
      spent_t += diff[2]
  return surface_to_array(surface).reshape(scale, scale, 1) 
開發者ID:google,項目名稱:mozc-devices,代碼行數:26,代碼來源:lib.py

示例3: setupCairo

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def setupCairo(self, outputFormat='png'):
        self.outputFormat = outputFormat
        if outputFormat == 'png':
            self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                              self.width, self.height)
        elif outputFormat == 'svg':
            self.surfaceData = BytesIO()
            self.surface = cairo.SVGSurface(self.surfaceData,
                                            self.width, self.height)
        elif outputFormat == 'pdf':
            self.surfaceData = BytesIO()
            self.surface = cairo.PDFSurface(self.surfaceData,
                                            self.width, self.height)
            res_x, res_y = self.surface.get_fallback_resolution()
            self.width = float(self.width / res_x) * 72
            self.height = float(self.height / res_y) * 72
            self.surface.set_size(self.width, self.height)
        self.ctx = cairo.Context(self.surface) 
開發者ID:brutasse,項目名稱:graphite-api,代碼行數:20,代碼來源:glyph.py

示例4: __init__

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def __init__(self, dpi):
        self.dpi = dpi
        self.gc = GraphicsContextCairo(renderer=self)
        self.text_ctx = cairo.Context(
           cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1))
        self.mathtext_parser = MathTextParser('Cairo')
        RendererBase.__init__(self) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:9,代碼來源:backend_cairo.py

示例5: draw_image

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def draw_image(self, gc, x, y, im):
        im = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(im[::-1])
        surface = cairo.ImageSurface.create_for_data(
            im.ravel().data, cairo.FORMAT_ARGB32,
            im.shape[1], im.shape[0], im.shape[1] * 4)
        ctx = gc.ctx
        y = self.height - y - im.shape[0]

        ctx.save()
        ctx.set_source_surface(surface, float(x), float(y))
        ctx.paint()
        ctx.restore() 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:14,代碼來源:backend_cairo.py

示例6: _get_printed_image_surface

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def _get_printed_image_surface(self):
        width, height = self.get_width_height()
        renderer = RendererCairo(self.figure.dpi)
        renderer.set_width_height(width, height)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
        renderer.set_ctx_from_surface(surface)
        self.figure.draw(renderer)
        return surface 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:10,代碼來源:backend_cairo.py

示例7: main

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def main(hexagon_size, imgsize):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imgsize, imgsize)
    ctx = cairo.Context(surface)

    # we will put the center of the hexagon at the origin
    a, b, c = hexagon_size
    ctx.translate(imgsize / 2.0, imgsize / 2.0)
    extent = max(c, a * HALFSQRT3, b * HALFSQRT3) + 1
    ctx.scale(imgsize / (extent * 2.0), -imgsize / (extent * 2.0))
    ctx.translate(-b * HALFSQRT3, -c / 2.0)

    # paint background
    ctx.set_source_rgb(1, 1, 1)
    ctx.paint()
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.set_line_join(cairo.LINE_JOIN_ROUND)

    T = LozengeTiling(hexagon_size)
    sample = run_cftp(T)
    for key, val in T.get_tiles(sample).items():
        for verts in val:
            A, B, C, D = square_to_hex(verts)
            ctx.move_to(A[0], A[1])
            ctx.line_to(B[0], B[1])
            ctx.line_to(C[0], C[1])
            ctx.line_to(D[0], D[1])
            ctx.close_path()
            if key == "T":
                ctx.set_source_rgb(*TOP_COLOR)
            elif key == "L":
                ctx.set_source_rgb(*LEFT_COLOR)
            else:
                ctx.set_source_rgb(*RIGHT_COLOR)
            ctx.fill_preserve()
            ctx.set_line_width(LINE_WIDTH)
            ctx.set_source_rgb(*EDGE_COLOR)
            ctx.stroke()

    surface.write_to_png("random_lozenge_tiling.png") 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:41,代碼來源:main.py

示例8: main

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def main(width, height, depth, xlim=None, ylim=None):
    if xlim is None:
        xlim = [-2, 2]
    if ylim is None:
        ylim = [0, 2]
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
    ctx = HyperbolicDrawing(surface)
    ctx.set_axis(xlim=xlim, ylim=ylim, background_color=(1, 1, 1))
    ctx.set_line_join(2)
    # draw the x-axis
    ctx.move_to(xlim[0], 0)
    ctx.line_to(xlim[1], 0)
    ctx.set_source_rgb(0, 0, 0)
    ctx.set_line_width(0.03)
    ctx.stroke()

    for word, _, triangle in traverse(depth, FUND_DOMAIN):
        if word:
            if word[0] == 'C':
                fc_color = (1, 0.5, 0.75)
            else:
                fc_color = None
        else:
            fc_color = (0.5, 0.5, 0.5)

        ctx.render_domain(triangle, facecolor=fc_color, linewidth=0.04/(len(word)+1))

    surface.write_to_png('modulargroup.png') 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:30,代碼來源:modulargroup.py

示例9: main

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def main():
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
    ctx = cairo.Context(surface)
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.set_line_join(cairo.LINE_JOIN_ROUND)
    ctx.set_source_rgb(1, 1, 1)
    ctx.paint()
    fractal_tree(ctx, ITERATIONS, ROOT, TRUNK_LEN,
                 RATIO, THETA, ANGLE, PERTURB)
    surface.write_to_png("random_fractal_tree.png") 
開發者ID:neozhaoliang,項目名稱:pywonderland,代碼行數:12,代碼來源:fractaltree.py

示例10: __init__

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def __init__(self, dpi):
        """
        """
        if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
        self.dpi = dpi
        self.gc = GraphicsContextCairo (renderer=self)
        self.text_ctx = cairo.Context (
           cairo.ImageSurface (cairo.FORMAT_ARGB32,1,1))
        self.mathtext_parser = MathTextParser('Cairo')

        RendererBase.__init__(self) 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:13,代碼來源:backend_cairo.py

示例11: print_png

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def print_png(self, fobj, *args, **kwargs):
        width, height = self.get_width_height()

        renderer = RendererCairo (self.figure.dpi)
        renderer.set_width_height (width, height)
        surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height)
        renderer.set_ctx_from_surface (surface)

        self.figure.draw (renderer)
        surface.write_to_png (fobj) 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:12,代碼來源:backend_cairo.py

示例12: scribe_text

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def scribe_text(text, font_style,
                width, height,
                x_offset, y_offset,
                rotation):

    fmt = cairocffi.FORMAT_A8
    width = cairocffi.ImageSurface.format_stride_for_width(fmt, width)
    data = array.array('b', [0] * (height * width))
    surface = cairocffi.ImageSurface(fmt, width, height, data, width)
    # pangocairo.pango_cairo_set_antialias(cairocffi.ANTIALIAS_SUBPIXEL)

    context = cairocffi.Context(surface)
    context.translate(x_offset, y_offset)
    context.rotate(rotation)
    layout = gobject_ref(pangocairo.pango_cairo_create_layout(context._pointer))
    pango.pango_layout_set_text(layout, text.encode('utf8'), -1)

    font_desc = pango.pango_font_description_from_string(font_style.encode('utf8'))
    pango.pango_layout_set_font_description(layout, font_desc)
    # pango.pango_layout_set_spacing(spc * 32)

    pangocairo.pango_cairo_update_layout(context._pointer, layout)
    pangocairo.pango_cairo_show_layout(context._pointer, layout)
    # print(surface.get_width(), surface.get_height())

    return np.frombuffer(data, dtype=np.uint8).reshape((height, width)) 
開發者ID:rakeshvar,項目名稱:chamanti_ocr,代碼行數:28,代碼來源:scribe_interface.py

示例13: render

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def render(self, scale=109, margin=1, line_width=0.35/25.4,
            bounds=None, show_bounds=True):
        if cairo is None:
            raise Exception('Drawing.render() requires cairo')
        bounds = bounds or self.bounds
        x1, y1, x2, y2 = bounds
        w = x2 - x1
        h = y2 - y1
        margin *= scale
        width = int(scale * w + margin * 2)
        height = int(scale * h + margin * 2)
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
        dc = cairo.Context(surface)
        dc.set_line_cap(cairo.LINE_CAP_ROUND)
        dc.set_line_join(cairo.LINE_JOIN_ROUND)
        dc.translate(margin, margin)
        dc.scale(scale, scale)
        dc.translate(-x1, -y1)
        dc.set_source_rgb(1, 1, 1)
        dc.paint()
        if show_bounds:
            dc.set_source_rgb(0.5, 0.5, 0.5)
            dc.set_line_width(1 / scale)
            dc.rectangle(x1, y1, w, h)
            dc.stroke()
        dc.set_source_rgb(0, 0, 0)
        dc.set_line_width(line_width)
        for path in self.paths:
            dc.move_to(*path[0])
            for x, y in path:
                dc.line_to(x, y)
        dc.stroke()
        return surface 
開發者ID:fogleman,項目名稱:axi,代碼行數:35,代碼來源:drawing.py

示例14: generate_image_direct_decomp

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def generate_image_direct_decomp(x_norm, x_diff_encoded, scale, stroke_width):
  """Generates image array from strokes using direction feature.

  Args:
    x_norm: [(x', y', t), ...] Normalized points.
    x_diff_encoded: [(dx, dy, dt, pendown), ...] Normalized diffs.
    scale (int): scale of the image.
    stroke_width (int): Brush thickness to draw.

  Returns:
    image (numpy.array): Image array with a shape of (scale, scale, 8).
  """

  surfaces = [cairo.ImageSurface(cairo.FORMAT_A8, scale, scale)
      for _ in range(8)]

  curr_x = x_norm[0][0]
  curr_y = x_norm[0][1]

  for i, diff in enumerate(x_diff_encoded):
    direction1, weight1, direction2, weight2 = get_direction(diff)

    ctx = cairo.Context(surfaces[direction1])
    ctx.move_to(curr_x * scale, curr_y * scale)
    ctx.set_line_width(stroke_width)
    ctx.set_source_rgba(1, 1, 1, weight1)
    ctx.line_to((curr_x + diff[0]) * scale, (curr_y + diff[1]) * scale)
    ctx.stroke()

    ctx = cairo.Context(surfaces[direction2])
    ctx.move_to(curr_x * scale, curr_y * scale)
    ctx.set_line_width(stroke_width)
    ctx.set_source_rgba(1, 1, 1, weight2)
    ctx.line_to((curr_x + diff[0]) * scale, (curr_y + diff[1]) * scale)
    ctx.stroke()

    curr_x += diff[0]
    curr_y += diff[1]

  return np.array([
    surface_to_array(surface) for surface in surfaces]).transpose(1, 2, 0) 
開發者ID:google,項目名稱:mozc-devices,代碼行數:43,代碼來源:lib.py

示例15: generate_image_plain

# 需要導入模塊: import cairocffi [as 別名]
# 或者: from cairocffi import ImageSurface [as 別名]
def generate_image_plain(x_norm, x_diff_encoded, scale, stroke_width):
  """Generates image array from strokes without direction feature.

  Args:
    x_norm: [(x', y', t), ...] Normalized points.
    x_diff_encoded: [(dx, dy, dt, pendown), ...] Normalized diffs.
    scale (int): scale of the image.
    stroke_width (int): Brush thickness to draw.

  Returns:
    image (numpy.array): Image array with a shape of (scale, scale, 1).
  """

  surface = cairo.ImageSurface(cairo.FORMAT_A8, scale, scale)

  curr_x = x_norm[0][0]
  curr_y = x_norm[0][1]

  for i, diff in enumerate(x_diff_encoded):
    ctx = cairo.Context(surface)
    ctx.move_to(curr_x * scale, curr_y * scale)
    ctx.set_line_width(stroke_width)
    if diff[3] == 1:
      ctx.set_source_rgba(1, 1, 1, 1)
    else:
      ctx.set_source_rgba(1, 1, 1, 0.5)
    ctx.line_to((curr_x + diff[0]) * scale, (curr_y + diff[1]) * scale)
    ctx.stroke()

    curr_x += diff[0]
    curr_y += diff[1]

  return surface_to_array(surface).reshape(scale, scale, 1) 
開發者ID:google,項目名稱:mozc-devices,代碼行數:35,代碼來源:lib.py


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