UIImagePNGRepresentation slow or am I doing something wrong?

孤街浪徒 提交于 2019-12-18 19:28:12

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/1224369/uiimagepngrepresentation-slow-or-am-i-doing-something-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!