4

So far I've managed to create an app for iPhone that takes multiple images with about a 3 second interval between each. 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. Then it takes about 12 seconds to save the image to the disk using JPEG representation.

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? I saw that the animations distract the user for a while, but still the time needed is below 12 seconds!

Thanks in advance.

1
  • Interesting question. Android seems to use the same code ("activity") for its own camera app that it does for third-party apps; this means it takes the same amount of time to save the image no matter where you take it from. Odd that Apple does not do something similar.
    – jrockway
    Oct 19, 2009 at 7:40

4 Answers 4

4

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). Apple should give the same functionality to its users but they are apple :)

2

I haven't tried this but I wouldn't be so sure that Apple isn't using the same methods. A big part of the Apple design philosophy relies on hiding operational interruptions from the user. 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.

If someone can't tell you how Apple actually does save faster I would suggest looking at ways to disguise the save time.

2
  • 1
    I know that Apple is hiding the save process with an animation but still, if you take a picture with their default camera app and then at the same time hit the home button to close the app, the process takes less then 12 seconds and the image is in the camera roll. For me this means that the saving part passes quicker that it would by the methods I know. That`s how i know that there is some other way to do that besides hiding the saving process.
    – worriorbg
    Oct 20, 2009 at 7:13
  • Just because a thumbnail shows up in the camera roll doesn't mean that the file has been completely saved. Apple may just create and display the thumbnail first while the file continues to save in the background. Unless you can actually watch the file on disk being created and closed, you don't know how long Apple is taking to carry out the file process. Trying to figure out how long the Apple operation takes based on clues from the interface is very unreliable because of the interface tricks that Apple routinely pulls.
    – TechZen
    Oct 20, 2009 at 13:57
0

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.

Guess you are out of luck for fast image saving

2
  • Thats what Im afraid of. I also think that there is some internal API that Apple makes use of, but why aren`t we suppose to use it. Is there another way to speed my saving besides using JPEG or PNG representation and NSData, maybe OpenGL or something?
    – worriorbg
    Oct 19, 2009 at 8:10
  • No answer on the web does not mean that there is no solution :-) Someone could have found one without having published it. As far as I've tested Apple approved apps, I can say it's possible. But... how... mystery.
    – Oliver
    Feb 23, 2012 at 17:46
0

I was having this problem in my app, on saving it would hang so I used 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. You can adapt this to suit your needs hopefully, will only work on iOS 4+. The code is ARC enabled.

-(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;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.