如何从ios的ipa应用包中拿出应用切图?

 一个ios的应用,我们把它从iTunes里面拖出来是一个ipa包,其实就是一个压缩包,可以手动将后缀名改为.zip, 解压出来就可以看到应用里面的资源文件,图片等,但是直接打开图片会发现是空白一片,不能预览。这是因为xcode在编译打包的时候会对资源文件中的png图片进行一些优化,所以解压出来的不能直接用。
   xcode对图片进行优化是使用一个工具pngcrush,在安装过xcode的mac机器上都已经存在。
  
   说一下改做法的意义啊,appStore上优秀的应用设计无数,通过这种方法就相当于拥有了一个庞大的png切图库,喜欢那个应用的图片就把它切图拿出来...
   下面放出方法:
   1、创建一个空白文件,我这里命名pngutil, 将下面的脚本代码拷进去,保存:
   

#!/bin/ksh

typeset current_path=$(pwd)

typeset output_path="${current_path}/output"

typeset png_file_list=`find ${current_path} -name "*.png"`

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=`find ${current_path} -type d -depth 1`

    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 "*.gif" -exec mv {} ${current_path} \;   
    find ${current_path} -name "*.jpeg" -exec mv {} ${current_path} \;
    find ${current_path} -name "*.jpg" -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,执行完毕就可以看到图片啦。

posted @ 2012-11-10 16:36  fengnianji  阅读(1599)  评论(0编辑  收藏  举报