简体   繁体   English

默认的相机iPhone应用程序如何设置如此快速地保存照片?

[英]How does the default Camera iPhone app manages to save a photo so fast?

So far I've managed to create an app for iPhone that takes multiple images with about a 3 second interval between each. 到目前为止,我已经设法为iPhone创建了一个应用程序,它可以拍摄多张图像,每张图像之间的间隔约为3秒。 I`m processing each image in a separate thread asynchronously and everything is great till it gets to the moment for saving the image on the iPhone disk. 我在一个单独的线程中异步处理每个图像,一切都很好,直到它将图像保存在iPhone磁盘上。 Then it takes about 12 seconds to save the image to the disk using JPEG representation. 然后,使用JPEG表示将图像保存到磁盘大约需要12秒。

How does Apple do it, how do they manage to save a single image so fast to the disk is there a trick they are using? Apple如何做到这一点,他们如何设法如此快速地将单个图像保存到磁盘上是否有他们正在使用的技巧? I saw that the animations distract the user for a while, but still the time needed is below 12 seconds! 我看到动画会分散用户一段时间的注意力,但仍然需要的时间低于12秒!

Thanks in advance. 提前致谢。

Actually apple uses its kernal driver AppleJPEGDriver, It is a hardware jpeg encoding api and is much faster than software encoding (JPEGRepresnetaion) and some of the people using it in their jailbreak apps(cycorder video recording application). 实际上苹果使用它的内核驱动程序AppleJPEGDriver,它是一个硬件jpeg编码api,比软件编码(JPEGRepresnetaion)和一些人在他们的越狱应用程序(循环视频录制应用程序)中使用它快得多。 Apple should give the same functionality to its users but they are apple :) Apple应该为用户提供相同的功能,但他们是苹果:)

I haven't tried this but I wouldn't be so sure that Apple isn't using the same methods. 我没试过这个但是我不太确定Apple没有使用相同的方法。 A big part of the Apple design philosophy relies on hiding operational interruptions from the user. Apple设计理念的一个重要部分依赖于隐藏用户的操作中断。 The Apple code may take as much time as yours but simply be adroit at hiding the entire save time from the perception of the user. Apple代码可能需要花费与您相同的时间,但只是熟练地将整个保存时间从用户的感知中隐藏起来。

If someone can't tell you how Apple actually does save faster I would suggest looking at ways to disguise the save time. 如果有人不能告诉你苹果实际上如何更快地保存,我会建议寻找方法来掩盖节省时间。

I was having this problem in my app, on saving it would hang so I used Grand central dispatch. 我在我的应用程序中遇到此问题,在保存它会挂起所以我使用Grand Central dispatch。

Below is the setImage method out of my image cache class, if UIImage has a image it saves it otherwise it deletes it. 下面是我的图像缓存类中的setImage方法,如果UIImage有一个图像,它会保存它,否则它会删除它。 You can adapt this to suit your needs hopefully, will only work on iOS 4+. 您可以根据自己的需要进行调整,只能在iOS 4+上运行。 The code is ARC enabled. 代码启用了ARC。

-(void)setImage:(UIImage *)image{
    if (image == nil){
    NSLog(@"Deleting Image");
    // Since we have no image let's remove the cached image if it exists
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                   NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
                   NSUserDomainMask, YES) objectAtIndex:0];
                   [[NSFileManager defaultManager] removeItemAtPath:[cachePath
                   stringByAppendingPathComponent:@"capturedimage.jpg"] error:nil];
                 });
    }
else {
      NSLog(@"Saving Image");
      // We've got an image, let's save it to flash memory.
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                     NSString *cachePath = 
                    [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
                    NSUserDomainMask, YES) objectAtIndex:0];
                    NSData *dataObj = UIImagePNGRepresentation(image);
                    [dataObj writeToFile:[cachePath 
                    stringByAppendingPathComponent:@"capturedimage.jpg"] atomically:NO];
                  });
     }

imageCache = image;

}

If you google around a bit... there is a whole bunch of people with the same problem. 如果你稍微谷歌...有一大堆人有同样的问题。

I didn't find an answer. 我找不到答案。 The general conclusion seems to be that apple either uses some internal api and bypass public api overhead or some hardware encoder. 一般的结论似乎是苹果要么使用一些内部api并绕过公共api开销或一些硬件编码器。

Guess you are out of luck for fast image saving 猜猜你没有快速保存图像的运气

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

相关问题 如何在iPhone设备的照片库中保存从相机捕获的图像? - How to save Capture image from camera in IPhone device Photo Library? 如何从默认的iOS相机应用程序向我的应用程序发送照片? - How to send a photo to my app from default iOS Camera app? 使用自定义名称将照片保存到iphone相机胶卷 - Save photo to iphone camera roll with a custom name iPhone:如何通过iPhone照片应用程序等“编辑”功能从照片库或相机中获取图像 - iPhone:How to fetch image from photo library or camera with “edit” funcitionality like iPhone photo app iPhone:如何将照片上的人标记为iPhone的Facebook应用? - iPhone: how to tag people on photo as facebook app for iPhone does? 如何在iPhone应用程序中将图像集保存到相册 - How to save set of images to photo gallery in iphone app 应用程序像iPhone中的默认照片浏览器一样? - App like default photo browser in iphone? iPhone:如何更改相机的照片质量 - iPhone: How to change camera photo quality 如何从Camera App隐藏照片,视频,全景图的搜索栏。 在Iphone中? - How to hide seekbar of photo ,video, panorama, from Camera App. in Iphone? iPhone相机和照片编辑选项-集成到自定义应用程序 - iPhone camera and photo editing options - integration on custom app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM