UIImagePNGRepresentation缓慢或我做错了什么? [英] UIImagePNGRepresentation slow or am I doing something wrong?

查看:112
本文介绍了UIImagePNGRepresentation缓慢或我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款使用相机拍照的iPhone App,然后我将它们保存到Applications Documents目录中。我正在使用以下代码将UIImage转换为NSData,

  NSData * imageData = [NSData dataWithData:UIImagePNGRepresentation(image) ]。 

然后我用



$ b <$ p写NSData $ p> [imageData writeToFile:path atomically:NO]

一切正常。问题是UIImagePNGRepresentation()非常慢。我的3G需要8-9秒才能将图像转换为NSData。这对我来说似乎不对。有人对这个有经验么?这只是缓慢的功能还是我做了一件非常糟糕的事情?



谢谢

解决方案

您确定要将用相机拍摄的照片保存为PNG吗?



JPEG是一种更合适的照片格式。另外,它可能要快得多!


I'm working on an iPhone App that uses the camera to take pictures, then I'm saving them to the Applications Documents directory. I'm using the following code to convert the UIImage to NSData,

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];

Then I write the NSData using

[imageData writeToFile:path atomically:NO]

It all works. The problem is that UIImagePNGRepresentation() is really slow. It takes 8-9 secs on my 3G to convert the image to NSData. This seems wrong to me. Does anyone have any experience with this? Is this just slow function or am I doing something terribly wrong?

Thanks

解决方案

Are you sure you want to save pictures captured with the camera as PNG?

JPEG is a more appropriate format for photographs. Additionally, its likely much faster!

这篇关于UIImagePNGRepresentation缓慢或我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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