当前位置: 首页>>代码示例>>Python>>正文


Python cairo.FORMAT_ARGB32属性代码示例

本文整理汇总了Python中cairo.FORMAT_ARGB32属性的典型用法代码示例。如果您正苦于以下问题:Python cairo.FORMAT_ARGB32属性的具体用法?Python cairo.FORMAT_ARGB32怎么用?Python cairo.FORMAT_ARGB32使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cairo的用法示例。


在下文中一共展示了cairo.FORMAT_ARGB32属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_image

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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)
        ctx.paint()
        ctx.restore()

        im.flipud_out() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:backend_cairo.py

示例2: draw_image

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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

示例3: NewImage

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def NewImage(self):
        """
This must be called before doing any rendering.
Note: this replaces any previous image drawn on so be sure to
retrieve the old image before calling it again to avoid losing work
"""
        #first mode
        mode = cairo.FORMAT_ARGB32
        #then other specs
        width = MAPWIDTH
        height = MAPHEIGHT
        background = MAPBACKGROUND
        self.img = cairo.ImageSurface(mode, int(MAPWIDTH), int(MAPHEIGHT))
        self.drawer = cairo.Context(self.img)
        if background:
            backgroundcolor = self.__hex_to_rgb(background)
            self.drawer.set_source_rgb(*backgroundcolor)
            self.drawer.rectangle(0,0,MAPWIDTH,MAPHEIGHT)
            self.drawer.fill() 
开发者ID:karimbahgat,项目名称:GeoVis,代码行数:21,代码来源:__init__.py

示例4: image2surface

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def image2surface(img):
    """
    Convert a PIL image into a Cairo surface
    """
    if not CAIRO_AVAILABLE:
        raise Exception("Cairo not available(). image2surface() cannot work.")

    # TODO(Jflesch): Python 3 problem
    # cairo.ImageSurface.create_for_data() raises NotImplementedYet ...

    # img.putalpha(256)
    # (width, height) = img.size
    # imgd = img.tobytes('raw', 'BGRA')
    # imga = array.array('B', imgd)
    # stride = width * 4
    #  return cairo.ImageSurface.create_for_data(
    #      imga, cairo.FORMAT_ARGB32, width, height, stride)

    # So we fall back to this method:
    global g_lock
    with g_lock:
        img_io = io.BytesIO()
        img.save(img_io, format="PNG")
        img_io.seek(0)
        return cairo.ImageSurface.create_from_png(img_io) 
开发者ID:openpaperwork,项目名称:paperwork-backend,代码行数:27,代码来源:util.py

示例5: svg2png

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def svg2png(svg_file, output_file, scale=1):
    # Get the svg files content
    svg_data = open(svg_file).read()

    # Get the width / height inside of the SVG
    doc = minidom.parseString(svg_data)
    width = [path.getAttribute('width') for path in doc.getElementsByTagName('svg')][0]
    height = [path.getAttribute('height') for path in doc.getElementsByTagName('svg')][0]
    width = int(round(float(re.compile('(\d+\.*\d*)\w*').findall(width)[0])))
    height = int(round(float(re.compile('(\d+\.*\d*)\w*').findall(height)[0])))
    doc.unlink()

    # Create the png
    img = cairo.ImageSurface(
        cairo.FORMAT_ARGB32, width * scale, height * scale)
    ctx = cairo.Context(img)
    ctx.scale(scale, scale)
    handler = rsvg.Handle(None, str(svg_data))
    handler.render_cairo(ctx)
    img.write_to_png(output_file)
    print("{} ==> {}".format(svg_file, output_file)) 
开发者ID:Geequlim,项目名称:godot-themes,代码行数:23,代码来源:svg2png.py

示例6: write_format1

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def write_format1 (self, png):

		import cairo
		img = cairo.ImageSurface.create_from_png (png.stream ())
		if img.get_format () != cairo.FORMAT_ARGB32:
			raise Exception ("Expected FORMAT_ARGB32, but image has format %d" % img.get_format ())

		width = img.get_width ()
		height = img.get_height ()
		stride = img.get_stride ()
		data = img.get_data ()

		self.write_smallGlyphMetrics (width, height)

		if sys.byteorder == "little" and stride == width * 4:
			# Sweet.  Data is in desired format, ship it!
			self.write (data)
			return

		# Unexpected stride or endianness, do it the slow way
		offset = 0
		for y in range (height):
			for x in range (width):
				pixel = data[offset + 4 * x: offset + 4 * (x + 1)]
				# Convert to little endian
				pixel = struct.pack ("<I", struct.unpack ("@I", pixel)[0])
				self.write (pixel)
			offset += stride 
开发者ID:samuelngs,项目名称:apple-emoji-linux,代码行数:30,代码来源:emoji_builder.py

示例7: __init__

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:backend_cairo.py

示例8: print_png

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:backend_cairo.py

示例9: on_draw_event

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def on_draw_event(self, widget, ctx):
        """ GtkDrawable draw event, like expose_event in GTK 2.X
        """
        allocation = self.get_allocation()
        w, h = allocation.width, allocation.height

        if not len(self._bbox_queue):
            if self._need_redraw:
                self._render_figure(w, h)
                bbox_queue = [transforms.Bbox([[0, 0], [w, h]])]
            else:
                return
        else:
            bbox_queue = self._bbox_queue

        for bbox in bbox_queue:
            area = self.copy_from_bbox(bbox)
            buf = np.fromstring(area.to_string_argb(), dtype='uint8')

            x = int(bbox.x0)
            y = h - int(bbox.y1)
            width = int(bbox.x1) - int(bbox.x0)
            height = int(bbox.y1) - int(bbox.y0)

            image = cairo.ImageSurface.create_for_data(
                buf, cairo.FORMAT_ARGB32, width, height)
            ctx.set_source_surface(image, x, y)
            ctx.paint()

        if len(self._bbox_queue):
            self._bbox_queue = []

        return False 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:backend_gtk3agg.py

示例10: __init__

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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

示例11: draw_image

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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

示例12: _get_printed_image_surface

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [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

示例13: create_png

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def create_png(text, output_path, **kwargs):
    """Creates a PNG image from the given text."""

    setup_fonts_conf()

    params = make_drawparams(**kwargs)
    temp_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 0, 0)
    calculated_height = draw_on_surface(temp_surface, text, params)

    real_surface = cairo.ImageSurface(
        cairo.FORMAT_ARGB32, params.width, calculated_height
    )
    draw_on_surface(real_surface, text, params)
    print("writing", output_path)
    real_surface.write_to_png(output_path) 
开发者ID:googlefonts,项目名称:nototools,代码行数:17,代码来源:create_image.py

示例14: write_format1

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def write_format1(self, png):

        import cairo

        img = cairo.ImageSurface.create_from_png(png.stream())
        if img.get_format() != cairo.FORMAT_ARGB32:
            raise Exception("Expected FORMAT_ARGB32, but image has format %d" % img.get_format())

        width = img.get_width()
        height = img.get_height()
        stride = img.get_stride()
        data = img.get_data()

        self.write_smallGlyphMetrics(width, height)

        if sys.byteorder == "little" and stride == width * 4:
            # Sweet.  Data is in desired format, ship it!
            self.write(data)
            return

        # Unexpected stride or endianness, do it the slow way
        offset = 0
        for y in range(height):
            for x in range(width):
                pixel = data[offset + 4 * x: offset + 4 * (x + 1)]
                # Convert to little endian
                pixel = struct.pack("<I", struct.unpack("@I", pixel)[0])
                self.write(pixel)
            offset += stride 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:31,代码来源:emoji_builder.py

示例15: scribe

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import FORMAT_ARGB32 [as 别名]
def scribe(text, fontname, ten=10, style=0,
           sz=48, spc=1, movex=10, movey=0, twist=0):
    lines = text.split('\n')
    n_lines = len(lines)
    n_letters = max(len(line) for line in lines)

    size_x = 3 * ten * n_letters + 5 * ten
    size_y = 5 * ten * n_lines + 5 * ten

    # print("Lines: {} Letters:{} Size:{}x{}".format(
    #     n_lines, n_letters, size_x, size_y))

    data = np.zeros((size_y, size_x, 4), dtype=np.uint8)
    surf = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32,
                                              size_x, size_y)
    cr = cairo.Context(surf)
    pc = pangocairo.CairoContext(cr)
    pc.set_antialias(cairo.ANTIALIAS_SUBPIXEL)

    layout = pc.create_layout()
    layout.set_text(text)

    style = styles[style]
    font_style = "{} {} {}".format(fontname, style, (sz * ten)//10)
    layout.set_font_description(pango.FontDescription(font_style))
    layout.set_spacing(spc * 32)

    cr.rectangle(0, 0, size_x, size_y)
    cr.set_source_rgb(1, 1, 1)
    cr.fill()
    cr.translate(ten, 0)
    cr.set_source_rgb(0, 0, 0)

    pc.update_layout(layout)
    pc.show_layout(layout)

    return data[:, :, 0] < 128 
开发者ID:rakeshvar,项目名称:chamanti_ocr,代码行数:39,代码来源:indic_scribe_python2.py


注:本文中的cairo.FORMAT_ARGB32属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。