如何从ipa包中获取png图片

一个ios的应用,我们把它从iTunes里面拖出来是一个ipa包,其实就是一个压缩包,可以手动将后缀名改为.zip, 解压出来就可以看到应用里面的资源文件,图片等,但是直接打开图片会发现是空白一片,不能预览。这是因为xcode在编译打包的时候会对资源文件中的png图片进行一些优化,所以解压出来的不能直接用。
xcode对图片进行优化是使用一个工具pngcrush,在安装过xcode的mac机器上都已经存在。

说一下改做法的意义啊,appStore上优秀的应用设计无数,通过这种方法就相当于拥有了一个庞大的png图库,喜欢那个应用的图片就把它切图拿出来…
下面放出方法:
1、创建一个空白文件,我这里命名pngutil, 将下面的脚本代码拷进去,保存:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/ksh
 
typeset current_path=$( pwd )
 
typeset output_path="${current_path} /output "
 
typeset png_file_list=<code> find ${current_path} -name &quot;*.png&quot;< /code >
 
function pngconvert
{
 
     mkdir -p ${output_path}
 
     for each in ${png_file_list}
     do
         typeset png_name=$( basename ${each})
 
             /Developer/Platforms/iPhoneOS .platform /Developer/usr/bin/pngcrush -revert-iphone-optimizations ${each} ${output_path}/${png_name}
 
     done
 
}
 
function clearsource
{
 
     typeset temp_file=<code> find ${current_path} - type d -depth 1< /code >
 
     for each in ${temp_file}
     do
 
         if [ ${each} != ${output_path} ]; then
             rm -rf $each
         fi
     done
 
     mv ${output_path}/* ${current_path}
 
     rm -rf ${output_path}
}
 
pngconvert
 
if [ $? - eq 0 ]; then
 
     find ${current_path} -name &quot;*.gif&quot; - exec mv {} ${current_path} \;
     find ${current_path} -name &quot;*.jpeg&quot; - exec mv {} ${current_path} \;
     find ${current_path} -name &quot;*.jpg&quot; - exec mv {} ${current_path} \;
 
     clearsource
 
fi

2、注意,脚本中的/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush路径就是你本机的pngcrush工具的路径,需要将此处改为你本机的路径,如果你是lion下的xcode4.2.1默认安装的,路径应该就是上面这个。

3、切换到root权限下,将刚创建的pngutil文件拷贝到/usr/bin/下, 然后改文件权限:
chmod 755 /usr/bin/pngutil

4、做完以上步骤应该就可以啦,可以测试下,先cd到ipa包的解压目录下面, 然后直接输入命令pngutil,执行完毕就可以看到图片啦。

本文转自:http://www.cnbluebox.com/?p=94

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值