jpg或png为UIImage - 这是更有效率? [英] jpg or png for UIImage -- which is more efficient?

查看:174
本文介绍了jpg或png为UIImage - 这是更有效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从相机胶卷中抓取图片,然后使用一段时间,并将其作为PNG在iPhone上保存到磁盘。我得到奇怪的崩溃,大概是由于内存不足。

I am grabbing an image from the camera roll and then using it for a while as well as save it to disk as a PNG on the iPhone. I am getting the odd crash, presumably due to out of memory.

如果我将它保存为PNG或JPG会有所不同(假设我选择注意降低JPG案例中的质量)?具体来说:

Does it make a difference if I save it as PNG or JPG (assuming I choose note to degrade the quality in the JPG case)? Specifically:


  • 是更多的内存,然后使用UIImage,如果我重新加载它从磁盘如果我将其保存为PNG? >
  • 是否可能在保存过程中暂时储存更多的内存?

我一直认为UIImage是一个格式中立的表示,它不应该重要,但我认为我应该验证。

I had been assuming the UIImage was a format neutral representation and it shouldn't matter, but I thought I should verify.

推荐答案

我有一个应用程序在商店,需要保存中间版本的图像,因为它正在编辑。在原始版本中,我使用PNG格式进行保存,以避免加载和多次保存JPEG时的质量损失。

I have an application on the store that needs to save intermediate versions of an image as it's being edited. In the original version, I used PNG format for saving, to avoid quality loss from loading and saving JPEG multiple times.

在2.2版本软件的某个时候,插入到PNG编写代码中,使得从一些图像保存PNG数据需要花费很多倍的时间。我最终不得不更改为以JPEG格式保存,因为我的应用程序在退出时尝试保存图片时超时。

Sometime around the 2.2 software release, Apple introduced a change into the PNG writing code, such that it takes many times longer to save PNG data from some images. I ended up having to change to saving in JPEG format, because my application was timing out when trying to save images on exit.

此外,您会遇到问题,以PNG格式保存不会保存UIImage中的方向信息,因此使用内置相机以纵向拍摄的照片将在保存并重新加载后显示为旋转。

Also, you'll run into issues because saving in PNG format doesn't preserve the "orientation" information in the UIImage, so a picture taken in Portrait orientation with the built-in camera will appear rotated after you save and reload it.

这篇关于jpg或png为UIImage - 这是更有效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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