本文整理汇总了Python中kivy.uix.image.Image.get_region方法的典型用法代码示例。如果您正苦于以下问题:Python Image.get_region方法的具体用法?Python Image.get_region怎么用?Python Image.get_region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.image.Image
的用法示例。
在下文中一共展示了Image.get_region方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_walls
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import get_region [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)
示例2: TileImage
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import get_region [as 别名]
class TileImage():
def __init__(self, source):
self.tile_size = (126,126)
self.texture = Image(source=source).texture
#def _set_texture(self, value):
#filename = resource_find(self.source)
#self.texture = CoreImage(filename)
#(x,y,width,height) = self.select_region()
#self.texture = self.texture.get_region(x,y,width,height)
#Logger.info('hi ' + str(self.texture) + ' ' + str(x) + ':' + str(y))
def get_region(self, pos):
num_wide = self.texture.size[0] / self.tile_size[0]
num_high = self.texture.size[1] / self.tile_size[1]
if num_high == 0 or num_wide == 0:
return (0,0,1,1)
if pos > num_wide * num_high:
return None
#this is an error
else:
#(x,y) = (0,0)
x = pos % num_wide * self.tile_size[0]
y = pos / num_wide * self.tile_size[1]
Logger.info('%d %d %d, %d %d',pos, num_wide, num_high, x, y )
#self.texture = self.image.texture.get_region(x,y,width,height)
r = Image(size=self.tile_size)
r.texture = self.texture.get_region(x,y,self.tile_size[0],self.tile_size[1])
return r
示例3: load_font
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import get_region [as 别名]
def load_font(state, font_name, font_path, font_w, font_h):
"""
TODO
"""
font_texture = Image(source=font_path).texture
code = 32
for y in xrange(8):
for x in xrange(12):
texture_name = font_name + "-" + str(code)
texture_db.insert(state, texture_name, font_texture.get_region(x * font_w, (7 - y) * font_h, font_w, font_h))
code += 1
state[IDX_STATE_TEXT][font_name] = [font_w, font_h]
示例4: load_image
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import get_region [as 别名]
def load_image(self):
self.data = {}
for path, dir_list, file_list in os.walk(self.image_dir):
for file_name in file_list:
name = '/'.join((path, file_name)).replace('\\', '/')
texture = Image(source=name).texture
x, y = texture.size
x_time = x / ShowBase.size
y_time = y / ShowBase.size
x_size = x / x_time
y_size = y / y_time
x_offset = x_size - ShowBase.size
y_offset = y_size - ShowBase.size
self.data[name] = {}
for i in xrange(x_time):
for j in xrange(y_time):
self.data[name][(i, j)] = texture.get_region(i * x_size + x_offset, j * y_size + y_offset, ShowBase.size, ShowBase.size)
示例5: add_image
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import get_region [as 别名]
def add_image(self, base_path, file):
if not os.path.exists(file):
file = os.path.join(base_path, file)
texture = Image(source=file).texture
texture.mag_filter = 'nearest'
if texture is None:
sys.exit('failed to locate image file %r' % file)
id = self.firstgid
th = self.tile_height + self.spacing
tw = self.tile_width + self.spacing
for j in xrange(texture.height / th):
for i in xrange(texture.width / tw):
x = (i * tw) + self.margin
# convert the y coordinate to OpenGL (0 at bottom of texture)
y = texture.height - ((j + 1) * th)
tile = texture.get_region(x, y, self.tile_width, self.tile_height)
self.tiles.append(Tile(id, tile, self))
id += 1