透明PNG图片占用空间较大,可以拆分为JPG图片和只带Alpha的PNG图片。这里使用ImageMagick进行拆分和合并实验。
ImageMagick版本:6.9.0-Q16
以Bird.png图片进行测试:
拆分透明PNG为JPG和只带Alpha的PNG
1 2 |
"D:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" Bird.png -background black -alpha remove Bird.jpg "D:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" Bird.png -alpha extract Bird_alpha_mask.png |
生成的Bird.jpg图片:
生成的Bird_alpha_mask.png图片:
合并JPG和只带Alpha的PNG为透明PNG
1 |
"D:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" Bird.jpg Bird_alpha_mask.png -compose copyopacity -composite Bird_with_alpha.png |
生成的Bird_with_alpha.png图片:
批处理:
拆分透明PNG为JPG和只带Alpha的PNG
1 2 3 4 5 6 7 |
@echo off set exevar="D:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" for /f "usebackq tokens=*" %%d in (`dir /s /b *.png`) do ( %exevar% "%%d" -background black -alpha remove "%%~dpnd.jpg" %exevar% "%%d" -alpha extract "%%~dpnd_alpha_mask.png" ) |
合并JPG和只带Alpha的PNG为透明PNG
1 2 3 4 5 6 |
@echo off set exevar="D:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" for /f "usebackq tokens=*" %%d in (`dir /s /b *.jpg`) do ( %exevar% "%%d" "%%~dpnd_alpha_mask.png" -compose copyopacity -composite "%%~dpnd_with_alpha.png" ) |
参考资料:
1. Transparent JPEG Images on iOS https://github.com/hollance/TransparentJPEG
2. cocos2dx中使用JPG图和只带Alpha的PNG图合成渲染 http://www.cnblogs.com/elang/p/4104452.html
3. Add an existing alpha data from image to another image http://www.wizards-toolkit.org/discourse-server/viewtopic.php?t=17529
4. Converting PNG to JPEG - black background http://www.imagemagick.org/discourse-server/viewtopic.php?t=24048