如何从ipa包中获取png图片

来源:互联网 发布:查企业法律纠纷的软件 编辑:程序博客网 时间:2024/05/24 07:24

一个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>
 
functionpngconvert
{
 
    mkdir-p ${output_path}
 
    foreach 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
 
}
 
functionclearsource
{
 
    typeset temp_file=<code>find${current_path} -typed -depth 1</code>
 
    foreach 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[ $? -eq0 ]; then
 
    find${current_path} -name &quot;*.gif&quot; -execmv {} ${current_path} \;
    find${current_path} -name &quot;*.jpeg&quot; -execmv {} ${current_path} \;
    find${current_path} -name &quot;*.jpg&quot; -execmv {} ${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

0 0
原创粉丝点击