标签:
实际操作非常没有技术含量,不过想展示一下万能的python。虽然python的文字编码和空格对齐我很反感,但是不得不说,其接口设计非常优秀,让复杂的工作变得非常简单,这种思想也体现在第三方扩展上面。
刀塔传奇使用jpg+mask文件的形式,达到压缩资源的目的。jpg的压缩比非常优秀,而mask含有透明通道信息,这样就可以大大压缩图片大小。
不过我个人更倾向于png,使用png8+压缩纹理不会比这个方案更差,换来的是更加快的加载速度和内存的节约。尤其是在Unity中,我更希望Unity来管理纹理,而不是我自己去操心。
#coding:utf-8
import os;
from PIL import Image;
# 将刀塔传奇中的mask+jpg文件转换成png文件
def doConvertJpg(jpgPath, maskPath):
pngPath = jpgPath.replace('.jpg', '.png');
maskData = open(maskPath, 'rb').read();
jpgData = open(jpgPath, 'rb').read();
jpg = Image.open(jpgPath);
width = jpg.size[0];
height = jpg.size[1];
png = jpg.convert('RGBA')
mask = Image.open(maskPath);
png.putalpha(mask);
png.save(pngPath);
os.remove(jpgPath);
os.remove(maskPath);
def doConvertPath(path):
for root, dirs, files in os.walk(path):
for file in files:
if file.find('.jpg') != -1:
fullPath = os.path.join(root, file);
maskPath = fullPath.replace('.jpg', '_alpha_mask');
if os.path.exists(maskPath):
doConvertJpg(fullPath, maskPath);
doConvertPath('ui');
os.system('PAUSE')将刀塔传奇中的jpg+mask文件转换为带透明通道的png文件
标签:
原文地址:http://blog.csdn.net/langresser_king/article/details/44454689