devsugar: Accessing an iPhone camera capture session

With the imminent demise of UIGetScreenImage, a number of readers have asked me how they can use the newer AVFoundation approach to access screen data in their iPhone applications. I went ahead and built some sample code that, when I'm finished messing with it, will be part of chapter 7 of my revised cookbook. I have uploaded the current version to github. It consists of a simple helper class that allows you to start and stop a capture session. You can request an image from this helper (namely, the last captured image from the buffer), which in this example is loaded into a central image view at the end-user's request. You can also ask it for a view with an embedded preview, using the current session. The example project adds that preview to the navigation bar.
I threw this example together pretty quickly, and as always, I welcome suggestions and improvements.
Share
With the imminent demise of UIGetScreenImage, a number of readers have asked me how they can use the newer AVFoundation approach to access...
Add a Comment
Hi Erica, thank you for the example. There is just so few information around there.
I've implemented something similar, but I wanted to trigger a captureStillImageAsynchronouslyFromConnection instead of using a low res frame. The problem is that I get a fuzzy image at the end. Continues autofocus is turned on.
Have you got any idea how to get a clear image, just like UIImagePickerController?
So thank you again for your help.
Hi Erica,
Thanks for whipping up the great demo app. I have a couple of questions
1. on 3GS snap function returns an image size of 480.000000 640.000000 and iPhone4 returns an image size of 720.000000 1280.000000. Those seem so arbitrary, are these related to original pixel size of the camera sensor?
2. While running the demo app, I keep on receiving memory warnings, and it crashes when I try to capture very quickly.
2010-07-23 12:54:26.515 HelloWorld[3731:307] Received memory warning. Level=2
Data Formatters temporarily unavailable, will re-try after a 'continue'.
Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib"
Thanks again for the help!
Great job except for this one bit:
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
Never ever ever ever EVER use the main dispatch queue. Performance will suffer and Apple just plain tells you not to.
Bad Erica, No Cookie :)
Instead, do something like this:
dispatch_queue_t queue = dispatch_queue_create("com.myapp.tasks.grabcameraframes", NULL);
[captureOutput setSampleBufferDelegate:self queue:queue];
When I try to compile it the SDK (4.0) throws 22 errors.
July 22 2010 at 6:29 PM Report abuse Permalink rate up rate down ReplySet the SDK to 4.0 Device. Update the Info.plist com.yourcompany. Sign with your own credentials.
July 22 2010 at 8:36 PM Report abuse Permalink rate up rate down Replysorry to side track ..but what happened to your devkit?
July 22 2010 at 12:48 PM Report abuse Permalink rate up rate down ReplyThanks a lot for this Erica. :)
July 21 2010 at 4:39 PM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
- Used Apple MacBook Pro 2.4GHz 15" LED Laptop for $1,030 + $29 s&h
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



8 Comments