博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单的实现了利用plist进行大图分割小图
阅读量:4355 次
发布时间:2019-06-07

本文共 2381 字,大约阅读时间需要 7 分钟。

1. 通过python简单的实现了plist图的切割

#如果plist里面有其他的属性可以根据需要自己进行添加修改#!pythonimport os,sysimport plistlibfrom PIL import Imagedef gen_png_from_plist(plist_filename, png_filename):    file_path = plist_filename.replace('.plist', '')    big_image = Image.open(png_filename)    root = plistlib.readPlist(plist_filename)    frames = root['frames']    to_list = lambda x: x.replace('{','').replace('}','').split(',')    to_int = lambda x:int(x)    for frame in frames:        # print(frame)        # print(frames[frame].spriteSize)        size = frames[frame].spriteSourceSize        size = to_list(size)        size = map(to_int, size)        spriteSize = frames[frame].spriteSize        spriteSize = to_list(spriteSize)        spriteSize = map(to_int, spriteSize)        textureRect = frames[frame].textureRect        textureRect = to_list(textureRect)        textureRect = map(to_int, textureRect)        result_box = textureRect        result_image = Image.new('RGBA', spriteSize, 0)        if frames[frame].textureRotated:            print('ttt')            result_box[0] = int(textureRect[0])            result_box[1] = int(textureRect[1])            result_box[2] = int(textureRect[0] + spriteSize[1])            result_box[3] = int(textureRect[1] + spriteSize[0])        else:            result_box[0] = int(textureRect[0])            result_box[1] = int(textureRect[1])            result_box[2] = int(textureRect[0] + spriteSize[0])            result_box[3] = int(textureRect[1] + spriteSize[1])        print(result_box, frames[frame].textureRotated, frame)                rect_on_big = big_image.crop(result_box)        if frames[frame].textureRotated:            rect_on_big = rect_on_big.transpose(Image.ROTATE_90)        result_image.paste(rect_on_big)        #result_image.show()        #break        if not os.path.isdir(file_path):            os.mkdir(file_path)        outfile = (file_path+'/' + frame)        print outfile, "generated"        result_image.save(outfile)            if __name__ == '__main__':    filename = sys.argv[1]    plist_filename = filename + '.plist'    png_filename = filename + '.png'    if (os.path.exists(plist_filename) and os.path.exists(png_filename)):        gen_png_from_plist( plist_filename, png_filename )    else:        print "make sure you have boith plist and png files in the same directory"

转载于:https://www.cnblogs.com/zjzyh/p/7326387.html

你可能感兴趣的文章
[LeetCode]Minimum Depth of Binary Tree
查看>>
jboss初体验
查看>>
Python列表、元组练习
查看>>
angular页面刷新
查看>>
Leetcode:7- Reverse Integer
查看>>
C6表单(方成eform)---自定义流程标题格式
查看>>
GridView下DropDownList 的选择方法onselectedindexchanged 实现方法
查看>>
Python之set集合
查看>>
Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle
查看>>
Win7 下新版本Windows Virtual PC 安装SharePoint步骤详解
查看>>
SQLSERVER 升级版本的方法
查看>>
atitit.web 推送实现方案集合
查看>>
VisualSVN和VisualSVN Server有区别,前者是客户端,后者是服务器端
查看>>
jquery1.8.3 callbacks源码分析
查看>>
Mac Anaconda 安装
查看>>
Vue2.0 新手入门 — 从环境搭建到发布
查看>>
带jdk15类似的jar配置
查看>>
redis基本操作
查看>>
从equals和==的区别开始
查看>>
Listview上下滚动崩溃
查看>>