【xcode】提取ipad中的png图片

本文介绍如何使用pngcrush命令行工具还原iOS SDK 3.2及以上版本在Xcode打包过程中优化过的PNG图片,以便查看原始图像。通过执行特定命令或使用GitHub上的工具,可以轻松实现这一过程。

这是因为在xcode打包ipa过程中,将图片使用pngcrush程序优化过了,具体的技术细节可以参看Apple的官方技术文档(英文)和Pngcrush的官方网站(英文)。那要如何将这些被优化过的图片“反优化”成可以浏览的图片文件呢?Apple的技术文档中给了相应的方法:

In iPhone SDK 3.2 and later, the pngcrush tool supports a command line option, -revert-iphone-optimizations, that undoes the optimizations done during the Xcode build process. So, to view an optimized PNG file, you should first undo the optimization and then open it with Preview.

?

方法就是,如果你使用的iOS SDK版本在3.2之后,在terminal里执行以下命令:

?

$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush\ -revert-iphone-optimizations -q Local.png Local-standard.png

?

当然,你也可以写一个script或者将script封装成一个Mac OS app来简化工作。不过,Github上已经有别人写好的,你只需要下载下来使用即可。 以上便是如何从封装好的ipa文件中提取图片文件的方法。

?

批量还原png的脚本如下,把以下代码复制,保存为“ruby uncrush.rb”文件,放置你的目标文件夹中,并运行,它会创建一个"uncrushed"文件夹,还原的png将放置在这里。

?

?

files = Dir.glob("*.png")

puts "Creating directory: uncrushed"
if File.directory?("uncrushed")
  puts "Directory already exists... delete and proceed? (y/n)"
  input = gets.strip
  if input == "y"
    deletefiles = Dir.glob("uncrushed/*.png")
    deletefiles.each do |f|
      File.delete(f)
    end
    Dir.delete("uncrushed")
  else
    abort
  end
else
end
Dir.mkdir("uncrushed")
files.each do |f|
  puts "Found file: #{f}... uncrushing it because we street!"
  `/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -revert-iphone-optimizations -q #{f} uncrushed/#{f}`
  puts "Creating new file: #{f}"
end

本文地址http://www.chengxuyuans.com/iPhone_IOS/40426.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值