简体   繁体   English

对于iOS上的所有图像文件,PNG是否优先于JPEG?

[英]Is PNG preferred over JPEG for all image files on iOS?

Xcode optimizes png images so they are loaded faster, but is this also recommended for other image resources that are not for buttons and UI (Photos for example)? Xcode优化了png图像,因此加载速度更快,但是对于不适用于按钮和UI的其他图像资源(例如照片),这也推荐使用吗?

Or is it a standard to have UI images as png and "photos" as JPEG? 或者将UI图像作为png和“照片”作为JPEG是标准吗?

What is the best practice here? 这里的最佳做法是什么?

The best practice is to use PNG files as often as possible when using images within your app. 最佳做法是在应用程序中使用图像时尽可能经常使用PNG文件。 iOS and Xcode load and display PNGs quickest as opposed to any other type of format. 与任何其他类型的格式相比,iOS和Xcode加载和显示PNG最快。 If given a choice, go with PNG. 如果有选择,请使用PNG。

When you use any other file type (or if you load a non-optimized PNG files), your iPhone has to do the byte-swapping and alpha premultiplication at load-time (and possibly re-do the alpha multiplication at display time). 当您使用任何其他文件类型(或者如果您加载非优化的PNG文件)时,您的iPhone必须在加载时进行字节交换和alpha预乘(并且可能在显示时重新进行alpha乘法)。 Your application basically has to do the same processing that Xcode does, but it's doing it at run-time instead of at build-time. 您的应用程序基本上必须执行与Xcode相同的处理,但它是在运行时而不是在构建时执行的。 This is going to cost you both in terms of processor cycles and memory overhead. 这将在处理器周期和内存开销方面花费您。 One of the reasons why Mobile Safari is the biggest memory hog of the built-in iPhone applications is because the images it has to load in order to display web-pages are all non-optimized images, mostly JPEGs. Mobile Safari是内置iPhone应用程序最大内存的原因之一是因为为了显示网页而必须加载的图像都是非优化图像,主要是JPEG。 Since JPEG is a compressed format, it has the added extra step of having to decompress the image into memory before it can do the premultiplication and byte-swapping. 由于JPEG是一种压缩格式,因此在进行预乘和字节交换之前,必须将图像解压缩到内存中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM