本文整理汇总了Python中kivy.graphics.Fbo.add方法的典型用法代码示例。如果您正苦于以下问题:Python Fbo.add方法的具体用法?Python Fbo.add怎么用?Python Fbo.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.Fbo
的用法示例。
在下文中一共展示了Fbo.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例2: make_screen_fbo
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [as 别名]
def make_screen_fbo(self, screen):
fbo = Fbo(size=screen.size)
with fbo:
ClearColor(0, 1, 0, 1)
ClearBuffers()
fbo.add(screen.canvas)
return fbo
示例3: save_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例4: export_as_image
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例5: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例6: toImage
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例7: make_screen_fbo
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [as 别名]
def make_screen_fbo(self, screen):
fbo = Fbo(size=screen.size)
with fbo:
ClearColor(*self.clearcolor)
ClearBuffers()
fbo.add(screen.canvas)
with fbo.before:
PushMatrix()
Translate(-screen.x, -screen.y, 0)
with fbo.after:
PopMatrix()
return fbo
示例8: FboCapture
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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)
示例9: toImage
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例10: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例11: make_screen_fbo
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [as 别名]
def make_screen_fbo(self, screen, mode=None):
assert(mode is not None)
attr = 'fbo_' + mode
fbo = getattr(self, attr)
w, h = screen.size
w = (w - w % TILE) + TILE
h = (h - h % TILE) + TILE
size = w, h
if not fbo:
fbo = Fbo(size=size)
setattr(self, attr, fbo)
fbo.clear()
with fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
fbo.add(screen.canvas)
fbo.draw()
return fbo
示例12: get_root_pixels
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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
示例13: _get_canvas_instructions
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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]
示例14: QuestionButton
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [as 别名]
class QuestionButton(Button):
disabled = BooleanProperty()
alpha_rotation = NumericProperty(0)
background_default = StringProperty()
background_wrong = StringProperty()
color_wrong = ListProperty([1, 1, 1, 0])
text_wrong = StringProperty()
def __init__(self, **kwargs):
super(QuestionButton, self).__init__(**kwargs)
self._origin = {}
Clock.schedule_once(self._prepare_fbo, 0)
def on_text(self, *args):
self._update_mesh()
def _prepare_fbo(self, *args):
# put all the current canvas into an FBO
# then use the fbo texture into a Quad, for animating when disable
# create the Fbo
self.fbo = Fbo(size=(1, 1))
with self.fbo.before:
self.g_translate = Translate(self.x, self.y)
self.orig_canvas = self.canvas
self.fbo.add(self.canvas)
# create a new Canvas
self.canvas = Canvas()
self.canvas.add(self.fbo)
with self.canvas:
Color(1, 1, 1)
self.g_quad = Quad(texture=self.fbo.texture)
# replace the canvas from the parent with the new one
self.parent.canvas.remove(self.orig_canvas)
self.parent.canvas.add(self.canvas)
# ensure we'll be updated when we'll change position
self.bind(pos=self._update_mesh, size=self._update_mesh, alpha_rotation=self._update_mesh)
self._update_mesh()
def _update_mesh(self, *args):
m = self.g_quad
alpha = self.alpha_rotation
# don't do anything if the fbo size will be messup.
if 0 in self.size:
return
# update fbo size, and reassign the new texture to the quad
if self.fbo.size != self.size:
self.fbo.size = self.size
self.g_quad.texture = self.fbo.texture
# change the background to red, and ensure we are not seeing any
# changes when clicking
if alpha >= 0.5: # and self.background_normal != self.background_wrong:
# self._origin = {
# 'background_normal': self.background_normal,
# 'background_down': self.background_down,
# 'color': (1, 1, 1, 1)}
self.background_normal = self.background_wrong
self.background_down = self.background_wrong
self.color = self.color_wrong
self.text = self.text_wrong
# correctly setup the positionning for the quad rendering
self.g_translate.xy = -self.x, -self.y
# 3d fake effect
dx = sin(alpha * pi / 2.0) * self.width
dy = sin(alpha * pi) * 25
if alpha > 0.5:
dy = -dy
dx = self.width - dx
m.points = (
self.x + dx,
self.y + dy,
self.right - dx,
self.y - dy,
self.right - dx,
self.top + dy,
self.x + dx,
self.top - dy,
)
def disable(self):
if self.alpha_rotation > 0:
return
d = 1.0
hd = 0.16 # at 0.16, the animation will be at the middle
t = "out_quart"
Animation(alpha_rotation=1.0, t=t, d=d).start(self)
(Animation(color=self.color_wrong, t=t, d=hd) + Animation(color=self.color, t=t, d=1 - hd)).start(self)
def reset(self, text):
self.alpha_rotation = 0
self.disabled = False
self.background_normal = "ui/screens/question/qbg.png"
#.........这里部分代码省略.........
示例15: export_to_png
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import add [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()