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


Python Fbo.draw方法代码示例

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


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

示例1: export_as_image

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def export_as_image(self, *args, **kwargs):
        '''Return an core :class:`~kivy.core.image.Image` of the actual
        widget.

        .. versionadded:: 1.11.0
        '''
        from kivy.core.image import Image
        scale = kwargs.get('scale', 1)

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                self.parent.canvas.remove(self.canvas)

        fbo = Fbo(size=(self.width * scale, self.height * scale),
                  with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(1, -1, 1)
            Scale(scale, scale, 1)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()
        img = Image(fbo.texture)
        fbo.remove(self.canvas)

        if self.parent is not None and canvas_parent_index > -1:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)

        return img
开发者ID:akshayaurora,项目名称:kivy,代码行数:35,代码来源:widget.py

示例2: export_to_png

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def export_to_png(self, filename, *args):
    '''Saves an image of the widget and its children in png format at the
    specified filename. Works by removing the widget canvas from its
    parent, rendering to an :class:`~kivy.graphics.fbo.Fbo`, and calling
    :meth:`~kivy.graphics.texture.Texture.save`.
    '''

    if self.parent is not None:
        canvas_parent_index = self.parent.canvas.indexof(self.canvas)
        self.parent.canvas.remove(self.canvas)

    fbo = Fbo(size=self.size,  with_stencilbuffer=True)

    with fbo:
        ClearColor(0, 0, 0, 1)
        ClearBuffers()
        Translate(-self.x, -self.y, 0)

    fbo.add(self.canvas)
    fbo.draw()
    fbo.texture.save(filename, flipped=False)
    fbo.remove(self.canvas)

    if self.parent is not None:
        self.parent.canvas.insert(canvas_parent_index, self.canvas)

    return True
开发者ID:dbuscombe-usgs,项目名称:lobos,代码行数:29,代码来源:lobos_v3.py

示例3: save_png

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def save_png(self, filename):
        if not self.done_draw: # Don't save a blank drawing.
            return False
        self.do_drawing = False
        ### Kivy 1.8.1 has an export_to_png function in the widget class. I'm not using 1.8.1 so I'm writing my own.
        ## Mostly copy-pasted from: https://github.com/kivy/kivy/blob/master/kivy/uix/widget.py (2014/06/16)
        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            self.parent.canvas.remove(self.canvas)
        fbo = Fbo(size=self.size_const)
        with fbo:
            ClearColor(0, 0, 0, 0) # I changed this from 0,0,0,1 to 0,0,0,0 so that I could have a transparent background.
            ClearBuffers()
            Translate(-self.draw_const[0], -self.draw_const[2], 0)

        fbo.add(self.canvas)
        fbo.draw()
        try:
            fbo.texture.save(filename)
            success = True
            kivy.logger.Logger.debug("PaintWidget: Saved file %s" % filename)
        except Exception as e:
            success = False
            kivy.logger.Logger.error("PaintWidget: Can't save file: %s" % filename)
            kivy.logger.Logger.exception(e)
        finally:
            fbo.remove(self.canvas)

            if self.parent is not None:
                self.parent.canvas.insert(canvas_parent_index, self.canvas)

            self.do_drawing = True
            return success
开发者ID:mijofa,项目名称:photo-guestbook,代码行数:35,代码来源:main.py

示例4: load_walls

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def load_walls(state, base_name, background_file, tile_file, with_collisions=True):
        """
        TODO
        """
        tile_size = screen.get_tile_size(state)
        int_tile_size = int(tile_size)
        background_texture = Image(source=background_file).texture
        walls_texture = Image(source=tile_file).texture
        for tile_name, origin_xy, collision in tiles_origin_table:
                full_tile_name = base_name + tile_name
                wall_texture = walls_texture.get_region(
                        origin_xy[0] * int_tile_size,
                        origin_xy[1] * int_tile_size,
                        int_tile_size,
                        int_tile_size)

                tile_texture = Texture.create(size=(int_tile_size, int_tile_size), colorfmt='rgba')
                fbo = Fbo(size=(int_tile_size, int_tile_size), texture=tile_texture)
                with fbo:
                        Color(1, 1, 1)
                        Rectangle(pos=(0, 0), size=tile_texture.size, texture=background_texture)
                        Rectangle(pos=(0, 0), size=tile_texture.size, texture=wall_texture)
                fbo.draw()
                if not with_collisions:
                        collision = None
                tiles.add_tile_def(state, full_tile_name, tile_texture, collision)
开发者ID:rkibria,项目名称:yapyg,代码行数:28,代码来源:tiles_helpers.py

示例5: export_to_png

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def export_to_png(self, filename, *args):
      

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                self.parent.canvas.remove(self.canvas)

        fbo = Fbo(size=self.size, with_stencilbuffer=True)

        with fbo:
            ClearColor(1, 1, 1, 1)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()
        fbo.texture.save(filename, flipped=False)
        fbo.remove(self.canvas)

        if self.parent is not None and canvas_parent_index > -1:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)

        return True
开发者ID:ansade,项目名称:PizarraEIE,代码行数:27,代码来源:pizarra.py

示例6: toImage

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def toImage(self, bg_color=(1,1,1,0)):
    #create image widget with texture == to a snapshot of me
    from kivy.graphics import Translate, Fbo, ClearColor, ClearBuffers, Scale
    from kivy.core.image import Image as CoreImage

    if self.parent is not None:
        canvas_parent_index = self.parent.canvas.indexof(self.canvas)
        self.parent.canvas.remove(self.canvas)

    fbo = Fbo(size=self.size, with_stencilbuffer=True)

    with fbo:
        ClearColor(*bg_color)
        ClearBuffers()
        Scale(1, -1, 1)
        Translate(-self.x, -self.y - self.height, 0)

    fbo.add(self.canvas)
    fbo.draw()
    #EventLoop.idle()
    cim = CoreImage(fbo.texture, filename = '%s.png'%id(self))

    fbo.remove(self.canvas)

    if self.parent is not None:
        self.parent.canvas.insert(canvas_parent_index, self.canvas)

    return cim
开发者ID:opqopq,项目名称:BoardGameMaker,代码行数:30,代码来源:__init__.py

示例7: FboTest

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
class FboTest(Widget):
    def __init__(self, **kwargs):
        super(FboTest, self).__init__(**kwargs)
        self.positions = [
            (260.0, 260.0),
            (192.0, 192.0),
            (96.0, 192.0),
            (192.0, 96.0),
            (96.0, 96.0),
            (32.0, 192.0),
            (192.0, 32.0),
            (32.0, 32.0)
        ]

        self.fbo = Fbo(size=(256, 256))
        with self.fbo:
            Color(0.56789, 0, 0, 1)
            Rectangle(size=(256, 64))
            Color(0, 0.56789, 0, 1)
            Rectangle(size=(64, 256))
            Color(0.56789, 0, 0, .5)
            Rectangle(pos=(64, 64), size=(192, 64))
            Color(0, 0.56789, 0, .5)
            Rectangle(pos=(64, 64), size=(64, 192))
        self.fbo.draw()
开发者ID:akshayaurora,项目名称:kivy,代码行数:27,代码来源:test_fbo_py2py3.py

示例8: circle_fs

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def circle_fs(size=(64, 64)):

    fbo = Fbo(size=size)
    fbo.shader.fs = circle_test

    with fbo:
        Color(1, 1, 1)
        Rectangle(size=size)
    fbo.draw()
    return fbo.texture
开发者ID:opqopq,项目名称:BoardGameMaker,代码行数:12,代码来源:effects.py

示例9: test_fbo_pixels

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def test_fbo_pixels(self):
        from kivy.graphics import Fbo, ClearColor, ClearBuffers, Ellipse

        fbo = Fbo(size=(512, 512))
        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Ellipse(pos=(100, 100), size=(100, 100))
        fbo.draw()
        data = fbo.pixels
        fbo.texture.save('results.png')
开发者ID:13768324554,项目名称:kivy,代码行数:13,代码来源:test_graphics.py

示例10: advanced_gradient

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def advanced_gradient(border_color=(1, 1, 0), center_color=(1, 0, 0), size=(64, 64),fs=radial_grd_fs):

    fbo = Fbo(size=size)
    fbo.shader.fs = fs

    # use the shader on the entire surface
    fbo['border_color'] = map(float, border_color)
    fbo['center_color'] = map(float, center_color)
    with fbo:
        Color(1, 1, 1)
        Rectangle(size=size)
    fbo.draw()

    return fbo.texture
开发者ID:opqopq,项目名称:BoardGameMaker,代码行数:16,代码来源:effects.py

示例11: hue_transform

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def hue_transform(source, hue, size=(64, 64)):

    fbo = Fbo(size=size)
    fbo.shader.fs = hue_xfo

    # use the shader on the entire surface
    fbo['hueAdjust'] = float(hue)

    with fbo:
        Color(1, 1, 1)
        Rectangle(size=size, source=source)
    fbo.draw()

    return fbo.texture
开发者ID:opqopq,项目名称:BoardGameMaker,代码行数:16,代码来源:effects.py

示例12: test_fbo_pixels

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def test_fbo_pixels(self):
        from kivy.graphics import Fbo, ClearColor, ClearBuffers, Ellipse

        fbo = Fbo(size=(512, 512))
        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Ellipse(pos=(100, 100), size=(100, 100))
        fbo.draw()
        data = fbo.pixels

        import pygame
        surface = pygame.image.fromstring(data, (512, 512), 'RGBA', True)
        pygame.image.save(surface, "results.png")
开发者ID:jeysonmc,项目名称:kivy,代码行数:16,代码来源:test_graphics.py

示例13: insert_color_ellipse

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
def insert_color_ellipse(state, texture_w, texture_h, texture_name, c_r, c_g, c_b):
        """
        TODO
        """
        tile_size = screen.get_tile_size(state)
        texture_w *= tile_size
        texture_h *= tile_size

        texture = Texture.create(size=(texture_w, texture_h), colorfmt='rgba')
        fbo = Fbo(size=(texture_w, texture_h), texture=texture)
        with fbo:
                Color(c_r, c_g, c_b)
                Ellipse(pos=(0, 0), size=(texture_w, texture_h))
        fbo.draw()
        insert(state, texture_name, texture)
开发者ID:erhuabushuo,项目名称:yapyg,代码行数:17,代码来源:texture_db.py

示例14: toImage

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def toImage(self, bg_color=(1,1,1,0), for_print = False):
        #print 'toImage with bg_color', self, bg_color
        #create image widget with texture == to a snapshot of me
        from kivy.graphics import Translate, Fbo, ClearColor, ClearBuffers, Scale
        from kivy.core.image import Image as CoreImage

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            self.parent.canvas.remove(self.canvas)


        if for_print:# make all not printed element disappear
            disappear = set()
            from fields import BaseField
            for children in self.walk():
                if not isinstance(children, BaseField):
                    continue
                if children.printed:
                    continue
                Logger.debug('Hiding item not printed %s'%children)
                disappear.add((children, children.opacity))
                children.opacity = 0

        fbo = Fbo(size=self.size, with_stencilbuffer=True)


        with fbo:
            ClearColor(*bg_color)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()

        cim = CoreImage(fbo.texture, filename='%s.png'%id(self))

        fbo.remove(self.canvas)

        if for_print:
            for (children, opacity) in disappear:
                children.opacity = opacity
        if self.parent is not None:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)
        return cim
开发者ID:opqopq,项目名称:BoardGameMaker,代码行数:47,代码来源:template.py

示例15: export_to_png

# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import draw [as 别名]
    def export_to_png(self, filename, *args):
        '''Saves an image of the widget and its children in png format at the
        specified filename. Works by removing the widget canvas from its
        parent, rendering to an :class:`~kivy.graphics.fbo.Fbo`, and calling
        :meth:`~kivy.graphics.texture.Texture.save`.

        .. note::

            The image includes only this widget and its children. If you want
            to include widgets elsewhere in the tree, you must call
            :meth:`~Widget.export_to_png` from their common parent, or use
            :meth:`~kivy.core.window.WindowBase.screenshot` to capture the whole
            window.

        .. note::

            The image will be saved in png format, you should include the
            extension in your filename.

        .. versionadded:: 1.9.0
        '''

        if self.parent is not None:
            canvas_parent_index = self.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                self.parent.canvas.remove(self.canvas)

        fbo = Fbo(size=self.size, with_stencilbuffer=True)

        with fbo:
            ClearColor(0, 0, 0, 1)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-self.x, -self.y - self.height, 0)

        fbo.add(self.canvas)
        fbo.draw()
        fbo.texture.save(filename, flipped=False)
        fbo.remove(self.canvas)

        if self.parent is not None and canvas_parent_index > -1:
            self.parent.canvas.insert(canvas_parent_index, self.canvas)

        return True
开发者ID:15huangtimothy,项目名称:kivy,代码行数:46,代码来源:widget.py


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