尝试获取纹理区域时出现分割错误

2024-09-30 16:23:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个简单的函数,从给定图像返回纹理区域:

from kivy.core.image import Image


def get_figure_texture(figure: Figure, img_path: str):
image = Image(img_path).texture
figures = {
    'white': {
        'king': (0, 0),
        'queen': (64, 0),
        'rook': (128, 0),
        'knight': (192, 0),
        'bishop': (256, 0),
        'pawn': (320, 0)
    },
    'black': {
        'king': (0, 64),
        'queen': (64, 64),
        'rook': (128, 64),
        'knight': (192, 64),
        'bishop': (256, 64),
        'pawn': (320, 64)
    }
}
offset = figures[figure.color_name][figure.name]

return image.texture.get_region(offset[0], offset[1], 64, 64)

然后,我想创建一个纹理:

 figure = Figure
 figure.name = 'king'
 figure.color_name = 'white'
 figure.texture - get_figure_texture(figure, 'res/figures.png')

当Kivy试图从给定的路径创建图像时,我在日志中看到:

[INFO   ] [Logger      ] Record log in 
/home/celtic/.kivy/logs/kivy_18-03-04_7.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pygame, 
img_gif (img_pil, img_ffpyplayer ignored)
/home/celtic/PycharmProjects/pygame-
tutorial/venv/lib/python3.6/importlib/_bootstrap.py:219: 
ImportWarning: can't resolve package from __spec__ or __package__, 
falling back on __name__ and __path__
return f(*args, **kwds)
Fatal Python error: (pygame parachute) Segmentation Fault

图像是384 x 128,我提供的路径是正确的,因为对于其他路径,我得到错误: AttributeError: 'NoneType' object has no attribute 'tell'。你知道吗


Tags: pathname图像image路径infoimgget