What’s the fastest way of getting a picture into a SQLite data store for compression, so I can return control to the user?
- I’m using
UIImagePickerControllerto take pictures in my application. The problem is using the picture is quite slow, because of the speed ofUIImageJPEGRepresentation. - I want to push JPEG compression into a background thread, but before trying this I need to satisfy myself that I can persist the picture in a way that will survive across runs. That means either a blob in SQLite or a file. Which as far as I can tell, takes me right back to doing slow picture encoding right away.
What I want to achieve is speed fast enough that it feels instant to the user.
How should I be handling this? Is there anything else I should know?
Based on comments and tests, here’s what I’m currently doing:
When I get the image from the
UIImageController, I retain it in a class ivar and dismiss the image picker. I show a view that blocks my main view and schedule a NSTimer event to do the compression in a second, then return to the caller.This lets the animation run that dismisses the image controller. My blocker view is revealed under it.
(The blocker view fills the entire content area of the navigation controller, and is solid black with a
UIActivityIndicatorView.)When the timer fires, I compress the image using JPEG (because it’s faster than PNG, despite intuition) and fade away the blocker view.
Although this adds a second do the processing, it gets the image picker out of the way faster so it no longer feels like my application has frozen. The animation from the
UIActivityIndicatorViewdoes run whileUIImageJPEGRepresentationis working.A better answer than using the
NSTimerwith 1 second delay would be to get an event when the animation fromdismissModalViewControllerAnimated:finishes, but I’m not sure how to do this.(I don’t consider this solved yet.)