本文整理汇总了Python中kivy.graphics.Fbo.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Fbo.remove方法的具体用法?Python Fbo.remove怎么用?Python Fbo.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.Fbo
的用法示例。
在下文中一共展示了Fbo.remove方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例2: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例3: export_as_image
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例4: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例5: toImage
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例6: FboCapture
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [as 别名]
class FboCapture(FloatLayout):
texture = ObjectProperty(None)
texture_thumb = ObjectProperty(None)
thumb_size = ListProperty([50, 50])
def __init__(self, **kwargs):
self.canvas = Canvas()
with self.canvas:
self.fbo = Fbo(size=self.size)
self.fbo_thumb = Fbo(size=self.thumb_size)
with self.fbo:
Color(0, 0, 0)
self.fbo_rect = Rectangle(size=self.size)
self.texture = self.fbo.texture
with self.fbo_thumb:
Color(1, 1, 1)
self.fbo_thumb_rect = Rectangle(size=self.thumb_size)
super(FboCapture, self).__init__(**kwargs)
def on_size(self, instance, value):
w, h = value
ratio = float(w) / h
if w > h:
w = 160
h = w / ratio
else:
h = 160
w = h * ratio
w = max(1, w)
h = max(1, h)
self.thumb_size = int(w), int(h)
self.fbo.size = value
self.fbo_rect.size = value
self.texture = self.fbo.texture
self.fbo_thumb_rect.texture = self.fbo.texture
def on_thumb_size(self, instance, value):
self.fbo_thumb.size = value
self.fbo_thumb_rect.size = value
self.texture_thumb = self.fbo_thumb.texture
def add_widget(self, child):
child.parent = self
self.children.insert(0, child)
self.fbo.add(child.canvas)
def remove_widget(self, child):
self.children.remove(child)
self.fbo.remove(child.canvas)
示例7: toImage
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例8: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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
示例9: get_root_pixels
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [as 别名]
def get_root_pixels(self):
widget = self.root.ids.display_canvas
canvas_parent_index = widget.parent.canvas.indexof(widget.canvas)
if canvas_parent_index > -1:
widget.parent.canvas.remove(widget.canvas)
fbo = Fbo(size=widget.size, with_stencilbuffer=True)
with fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
Scale(1, -1, 1)
Translate(0, -widget.height, 0)
fbo.add(widget.canvas)
fbo.draw()
pixels = fbo.pixels
fbo.remove(widget.canvas)
if canvas_parent_index > -1:
widget.parent.canvas.insert(canvas_parent_index, widget.canvas)
return pixels, widget.size
示例10: _get_canvas_instructions
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [as 别名]
def _get_canvas_instructions(self):
""" Returns canvas instructions used to manipulate the visual appearance
of the widget. Canvas instructions from here are singleton, that way
to parallel animation can operate on the same set of instructions"""
if self.uid in CanvasWidget._reg:
CanvasWidget._reg[self.uid][-1] += 1
else:
widget = self.widget
# Grab widget.canvas texture. (From Widget.export_to_png)
if widget.parent is not None:
canvas_parent_index = widget.parent.canvas.indexof(
widget.canvas)
if canvas_parent_index > -1:
widget.parent.canvas.remove(widget.canvas)
fbo = Fbo(size=widget.size, with_stencilbuffer=True)
with fbo:
Translate(-widget.x, -widget.y, 0)
fbo.add(widget.canvas)
fbo.draw()
fbo.remove(widget.canvas)
if widget.parent is not None and canvas_parent_index > -1:
widget.parent.canvas.insert(canvas_parent_index, widget.canvas)
# End grab
c = (1, 1, 1, 1) if not self._debug else (1, 0, 1, 0.5)
with self.root_widget.canvas:
PushMatrix()
scale = Scale(1, 1, 1)
rotate = Rotate(angle=0, axis=(0, 0, 1))
color = Color(*c)
rect = Rectangle(
size=widget.size, pos=widget.pos, texture=fbo.texture)
PopMatrix()
CanvasWidget._reg[self.uid] = [scale, rotate, color, rect, 1]
return CanvasWidget._reg[self.uid][:-1]
示例11: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import remove [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.Window.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.8.1
'''
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 fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
Translate(-self.x, -self.y, 0)
fbo.add(self.canvas)
fbo.draw()
fbo.texture.save(filename)
fbo.remove(self.canvas)
if self.parent is not None:
self.parent.canvas.insert(canvas_parent_index, self.canvas)
return True
kv = '''
cameraWidget:
orientation: 'vertical'
Camera:
id: camera
resolution: (640, 480)
play: False
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: "Take picture"
on_press: root.TakePicture()
height: '48dp'
'''
class cameraWidget(BoxLayout):
def TakePicture(self, *args):
self.export_to_png = export_to_png
self.export_to_png(self.ids.camera, filename='test2.png')
class MyApp(App):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
MyApp().run()