本文整理汇总了Python中kivy.graphics.Fbo.release方法的典型用法代码示例。如果您正苦于以下问题:Python Fbo.release方法的具体用法?Python Fbo.release怎么用?Python Fbo.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.Fbo
的用法示例。
在下文中一共展示了Fbo.release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainImageWidget
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import release [as 别名]
class MainImageWidget(Widget):
def __init__(self):
Widget.__init__(self)
self.fbo = None
self.fbo_pos = None
self.fbo_size = None
self.fbo_real_size = None
self.fbo_scale = None
def _init_fbo(self):
if self.fbo_pos is None:
self.fbo_pos = self.pos
self.fbo_size = self.size
self.fbo_real_size = self.size
self.fbo_scale = 1
with self.canvas:
#self.fbo = Fbo(size=self.fbo_size)
self.fbo = Fbo(size=self.fbo_real_size)
# Rectangle(size=self.fbo_size, texture=self.fbo.texture, pos=self.fbo_pos)
Rectangle(size=self.fbo_size, texture=self.fbo.texture,
pos=(self.fbo_pos[0],
self.fbo_pos[1]))
def on_touch_down(self, touch):
if self.fbo is None:
self._init_fbo()
#touch position must be corrected with widget postion in order to draw in the fbo
touch.x -= self.fbo_pos[0]
touch.x *= self.fbo_scale
touch.y -= self.fbo_pos[1]
touch.y *= self.fbo_scale
with self.fbo:
Color(1, 1, 0)
d = 10.
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
touch.ud['line'] = Line(points=(touch.x, touch.y), width=10) #in fbo kivy uses gl_line so with is always 1
def on_touch_move(self, touch):
#touch position must be corrected with widget postion in order to draw in the fbo
touch.x -= self.fbo_pos[0]
touch.x *= self.fbo_scale
touch.y -= self.fbo_pos[1]
touch.y *= self.fbo_scale
touch.ud['line'].points += [touch.x, touch.y]
def read_draw_layer(self, raw=True):
self.fbo.bind()
#pixels = glReadPixels(self.fbo_pos[0], self.fbo_pos[1], self.fbo.size[0], self.fbo.size[1], GL_RGBA, GL_UNSIGNED_BYTE)
pixels = glReadPixels(0, 0, self.fbo.size[0], self.fbo.size[1], GL_RGBA, GL_UNSIGNED_BYTE)
self.fbo.release()
if not raw:
#get ints
pixels = [ord(pixel) for pixel in pixels]
#convert to tuple format
pixels = zip(pixels[0::4], pixels[1::4],pixels[2::4], pixels[3::4])
return pixels
def SetImageInWidget(self, image):
if self.fbo is None:
self._init_fbo()
#show the image in kivy
if image.get_bytesize() == 3:
fmt = 'rgb'
elif image.get_bytesize() == 4:
fmt = 'rgba'
data = pygame.image.tostring(image, fmt.upper(), True)
k_im_data = ImageData(image.get_width(), image.get_height(), fmt, data)
imageTexture = Texture.create_from_data(k_im_data)
self.canvas.clear()
#Modify size and offset to avoid image distortion
orig_h = image.get_height()
orig_w = image.get_width()
wid_h = self.size[1]
wid_w = self.size[0]
print self.size
s_size = (0,0)
offset = (0,0)
orig_ratio = float(orig_w)/orig_h
wid_ratio = float(wid_w)/wid_h
if wid_ratio > orig_ratio: #fix height
s_size = (int(wid_h*orig_ratio), wid_h)
offset = ((wid_w - s_size[0])/2, 0)
self.fbo_scale = float(orig_h)/wid_h #scale factor to recover the original image size
else: #fix width
s_size = (wid_w, int(wid_w/orig_ratio))
offset = (0, (wid_h - s_size[1])/2)
self.fbo_scale = float(orig_w)/wid_w #scale factor to recover the original image size
self.fbo_pos = (self.pos[0] + offset[0], self.pos[1] + offset[1])
#self.fbo_pos = (self.pos[0] + offset[0]*self.fbo_scale, self.pos[1] + offset[1]*self.fbo_scale)
self.fbo_size = s_size
self.fbo_real_size = (orig_w, orig_h)
#self.canvas.add(Rectangle(texture=imageTexture, pos = self.fbo_pos,
#.........这里部分代码省略.........