---
title: "从ipa中提取png图片"
author: "shake863"
date: "2012-12-13T12:07:18Z"
tags: []
categories: ["移动开发"]
slug: "ipa-png"
draft: false
lastmod: "2012-12-13T12:07:18Z"
id: 1747026
url: "https://shake863.iteye.com/blog/1747026"
---

解压ipa 在windows下不能查看图片，在mac下虽然一部分能够查看，但是一些是不能查看的，原因是因为ipa在打包的时候  
经过一个叫Pngcrush的家伙做了png优化，所以，我们也可以用这个家伙来反转回来，以供学习之用。

 

具体的技术细节可以参看Apple的官方技术文档（英文）和Pngcrush的官方网站（英文）。那要如何将这些被优化过的图片“反优化”成可以浏览的图片文件呢？Apple的技术文档中给了相应的方法：

 

```
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!"
  `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush -revert-iphone-optimizations -q #{f} uncrushed/#{f}`
  puts "Creating new file: #{f}"
end
```