将从 Adobe Animate 导出的纹理图集转换为图像

问题描述 投票:0回答:1

我想知道如何将纹理图集转换为图像。 为了解决这个问题,我尝试了很多搜索,甚至尝试分析文件,但这对我来说太困难了。 它包含Animation.json,spritemap1.json,spritemap1.png。

Animation.json写的字典太难了,我无法分析它。 虽然我主要使用Python,但我也愿意尝试其他东西。 我做了一些分析,并尝试将其转换为图像,但 PILLOW 的图像粘贴方法太复杂,所以即使这样也失败了。

python textures adobe-animate
1个回答
0
投票
  1. 使用json读取JSON文件内容(Animation.json和spritemap1.json)
  2. 分析这些文件的信息以提取地图集不同部分的坐标和尺寸。
  3. 使用 Pillow 加载主图像(spritemap1.png)
  4. 使用提取的坐标剪切主图像的不同部分。
  5. 将每个部分保存为图像。
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!")
© www.soinside.com 2019 - 2024. All rights reserved.