我想知道如何将纹理图集转换为图像。 为了解决这个问题,我尝试了很多搜索,甚至尝试分析文件,但这对我来说太困难了。 它包含Animation.json,spritemap1.json,spritemap1.png。
Animation.json写的字典太难了,我无法分析它。 虽然我主要使用Python,但我也愿意尝试其他东西。 我做了一些分析,并尝试将其转换为图像,但 PILLOW 的图像粘贴方法太复杂,所以即使这样也失败了。
import json
from PIL import Image
# Load content of file Animation.json
with open('Animation.json', 'r') as animation_file:
animation_data = json.load(animation_file)
# Load content of file spritemap1.json
with open('spritemap1.json', 'r') as spritemap_file:
spritemap_data = json.load(spritemap_file)
# Load main image
image = Image.open('spritemap1.png')
# Extraction of coordinates and dimensions from data animation
for animation_name, animation_info in animation_data.items():
frame = animation_info['frame']
x, y, width, height = spritemap_data[frame]['frame']
# Crop image from coordinates
sprite = image.crop((x, y, x + width, y + height))
# Save image
sprite.save(f'{animation_name}.png')
print("finished!")