在外部下载的PNG上执行iPhone优化 [英] Performing iPhone optimization on externally downloaded PNGs

查看:126
本文介绍了在外部下载的PNG上执行iPhone优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将PNG添加到XCode iPhone项目时,编译器会使用pngcrush对其进行优化。一旦在设备上,图像的渲染性能非常快。

When a PNG is added to an XCode iPhone project, the compiler optimizes it using pngcrush. Once on the device, the image's rendering performance is very fast.

我的问题是我的应用程序在运行时从外部源下载PNG(来自Picasa网络相册,使用谷歌数据API)。不幸的是,这些图像的表现相当糟糕。当我在图像上进行自定义渲染时,它似乎比内部存储的对应物慢100倍。我强烈怀疑这是因为下载的图像尚未优化。

My problem is that my application downloads its PNGs from an external source at runtime (from Picasa Web albums, using the Google Data APIs). Unfortunately, these images' performance is quite bad. When I do custom rendering on top of the image, it seems 100x slower than its internally stored counterparts. I strongly suspect this is because the downloaded images haven't been optimized.

有谁知道如何在iPhone上运行时优化外部下载的PNG?我希望上课能做到这一点。我甚至考虑将pngcrush的源代码添加到我的应用程序中,这似乎很激烈。我自己一直无法找到合适的答案。我非常感谢你的帮助。

Does anyone know how I can optimize an externally downloaded PNG at runtime on the iPhone? I'm hoping for a class that does this. I even considered adding pngcrush's source code to my app, which seems drastic. I haven't been able to find an decent answer myself. I'd be very grateful for any help.

谢谢!

更新:
有些人建议它可能是由于文件的大小,但事实并非如此。在我的测试中,我添加了一个切换按钮,在使用嵌入版本和完全相同的PNG的下载版本之间切换。唯一的区别是嵌入的一个在编译期间被'pngcrush'优化。这会进行一些字节交换(从RGBA到BRGA)和alpha的预乘。 ( http://iphonedevelopment.blogspot.com/2008/10/iphone- optimize-pngs.html

另外,我所指的性能不是下载,而是渲染。我在图像顶部叠加了自定义绘画(覆盖了UIView的drawRect方法),当背景是下载版本时它非常不连贯,而当它是嵌入(并因此优化)版本时非常平滑。同样,它是完全相同的文件。唯一的区别是优化,我希望我可以在运行时,在设备上,在下载后在图像上执行。

Also, the performance I'm referring to isn't the downloading, but the rendering. I superimpose custom painting on top of the image (overriding the drawRect method of the UIView), and it's very choppy when the background is the downloaded version, and very smooth when it's the embedded (and therefore optimized) version. Again, it's exactly the same file. The only difference is the optimization, which I'm hoping I can perform on the image at runtime, on the device, after downloading it.

再次感谢大家的帮助!

Thanks again for everyone's help!

推荐答案

您发布的链接几乎可以回答您的问题。

That link you posted pretty much answers your question.

在构建过程中,XCode会预处理你的png,因此它的格式对iPhone中的图形芯片更友好。

During the build process XCode pre-processes your png so it's in a format that's more friendly to the graphics chip in the iPhone.

没有像这样处理过的Png可能会使用较慢的渲染路径,一个处理非原生格式的路径以及必须单独计算alpha的事实对于每种颜色。

Png's that have not been processed like this will likely use a slower rendering path, one that deals with the non-native format and the fact that the alpha must be computed separately for each color.

所以你有两个选择;


  1. 执行与pngcrush相同的工作并交换排序/预乘alpha。加速可能是由于这些中的一个或两个。

  1. Perform the same work that pngcrush does and swap ordering/pre-multiply alpha. The speed up may be due to one or both of these.

加载图像后,您可以从中创建新图像。这个新图像应该是iPhone的原生格式,所以应该更快。缺点是它可能会占用更多的内存。

After you have loaded your image, you can "create" a new image from it. This new image should be in the iPhone's native format and so should perform faster. The downside is it could potentially take up a bit more memory.

例如

CGRect area = CGRectMake(0, 0, width, height);
CGSize size = area.size;
UIGraphicsBeginImageContext(size);

[oldImage drawInRect:area];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这篇关于在外部下载的PNG上执行iPhone优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆