Hi,
Not really easy, but not that hard too.
The first thing is to render your widget on a FBO, and then, extract the
pixels and save it to a file.
It would look like this: (not tested)
import pygame
from kivy.graphics.fbo import Fbo
from
kivy.core.gl import glReadPixels, GL_RGBA, GL_UNSIGNED_BYTE
from kivy.graphics.texture import Texture
def widgetshot(widget, filename='output.png'):
# detach the widget from the parent
parent = widget.parent
if parent:
parent.remove_widget(widget)
# put the widget canvas on a Fbo
texture = Texture.create(size=widget.size, colorfmt='rgb')
fbo = Fbo(size=widget.size, texture=texture)
fbo.add(widget.canvas)
# clear the fbo background
fbo.bind()
fbo.clear_buffer()
fbo.release()
# draw!
fbo.draw()
# get the fbo data
fbo.bind()
data = glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE)
fbo.release()
# save to a file
surf = pygame.image.fromstring(data, widget.size, 'RGBA', True)
pygame.image.save(surf, filename)
# reattach to the parent
if parent:
parent.add_widget(widget)
return True
Le 07/12/2012 07:11, Jason Kuen a �crit :
> --
>
>