游戏图集分割程序
本程序只对游戏图集做简单的处理,需要有
json配置文件与图集文件
运行环境
-
python 3.6 +
-
opencv-python
pip install opencv-python
案例
- 目录
|--split
|--|--imgs //用于存储分割后的散图
|--|--index.py
|--|--res.json //图集配置文件(以LayaBox的图集为例)
|--|--res.png //图集(以LayaBox的图集为例)
- index.py
# -*- coding: utf-8 -*-
import json
import cv2
# 读取图集
imgMax = cv2.imread('res.png', cv2.IMREAD_UNCHANGED)
# 读取图集配置文件
with open('res.json', 'r') as load_f:
load_dict = json.load(load_f)
imgs = load_dict.get('frames')
# 遍历配置并保存散图
for imgName in imgs:
d = imgs[imgName]
img = imgMax[d['y']:d['y']+d['h'], d['x']:d['x']+d['w']]
cv2.imwrite('imgs/' + imgName + '.png', img)