如何跳过压缩一张 PNG?
(注意:我已经解决了这个问题,但花了足够长的时间才在这里发布问题/答案。)
Xcode 构建过程在构建时“优化”我的 PNG。这通常不是问题,但以这种方式处理的 iTunesArtwork 会导致其损坏,以致 iTunes 无法显示它。我怎样才能防止这种情况发生?
(Note: I have solved this problem, but it took long enough that I'm posting question/answer here.)
The Xcode build process "optimizes" my PNGs when building. This isn't usually a problem, but iTunesArtwork being processed in this way causes corrupts it so that iTunes not to be able to show it. How can I prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在此处阅读有关 Xcode 的 PNG 压缩的更多信息:
http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized -pngs.html
虽然您可以在项目设置中使用“压缩 PNG 文件”完全关闭 PNG 优化/压缩(仅当项目的 Base SDK 设置为设备 SDK,而不是模拟器 SDK 时才可见),你不想这样做!阅读上面的链接了解原因的详细信息,但其要点是优化让 iPhone 跳过一些减慢 PNG 显示速度的数学运算。
Xcode 只会优化它所知道的 PNG 图像文件。为了防止优化特定的 PNG,您可以更改其文件类型,以便 Xcode 不再知道它是 PNG。
image.png
更改为file
。(这实际上是当您添加不带扩展名的文件时的默认设置,这可能就是 iTunesArtwork 没有扩展名的原因。但如果您像我一样迂腐,您可以检查“文件类型”设置并修复它。)
You can read more about Xcode's PNG compression here:
http://iphonedevelopment.blogspot.com/2008/10/iphone-optimized-pngs.html
While you can turn off PNG optimization/compression entirely using "Compress PNG Files" in your project settings (it's visible only if the project's Base SDK is set to a device SDK, not a simulator SDK), you don't want to do this! Read the link above for details on why, but the gist of it is that the optimization lets the iPhone skip some math that slows down PNG display.
Xcode will only optimize PNG image files that it knows about. To prevent a specific PNG from being optimized, you change its file type so Xcode no longer knows it's a PNG.
image.png
tofile
.(This is actually the default when you add a file without an extension, which is presumably why iTunesArtwork doesn't have one. But if you're pedantic like me you checked the File Type setting and fixed it.)
找到了另一种非常简单的方法来禁用单个 png 文件的压缩。我认为这是比接受的答案更好的方法,因为您不必更改本地文件系统中的文件类型(或扩展名),而只需在 XCode 中更改。
在 XCode 的身份和类型检查器中将文件类型从
Default - PNG Image
更改为Data
。参见下文:以前:
现在:
Found another very simple method to disable compression for a single png file. I think this is a better approach than the accepted answer because you don't have to change type (or extension) of file in the local file-system but only in XCode.
Change the file type from
Default - PNG Image
toData
in Identity and Type inspector in XCode. See below:Was:
Now:
对于所有使用 Xcode 6.4 及更高版本的人:
转到:“Targets”-“YourProject Name”。
接下来转到“构建设置”选项卡。在选项卡名称下方单击“基本”和“组合”按钮。
接下来向下滚动到“打包”分隔符,您会发现“压缩 PNG 文件”默认设置为“是”。
For all you guys using Xcode 6.4 and above:
Go to: "Targets" - "YourProject Name".
Next go to the "Build Settings" tab. Just below the Tab name click the "Basic" and "Combined" Button.
Next scroll down to the "Packaging" seperator and you will find "Compress PNG Files" set to "Yes" by default.
在此之后,将避免 PNG 图像的压缩。
只是为了了解更多信息
After this compression of PNG images will be avoided.
Just For more info