Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an image representation of the camera preview in UIImagePickerController

Tags:

iphone

When I use the standard [view.layer renderInContext:UIGraphicsGetCurrentContext()]; method for turning views into images on the iPhone camera modal view, all I get is the controls with black where the camera preview was.

Anyone have a solution for this? Speed is not an issue.

like image 465
3n. Avatar asked Mar 02 '09 05:03

3n.


2 Answers

You can do this with the new AVFoundation stuff in iOS 4.0.

You should be able to call UIGetScreenImage() (returns a UIImage) to get a current capture of the whole screen, including the preview. That's how all the barcode apps worked before. But supposedly Apple is disallowing that now and only allow the AVFoundation technique - which only works under 4.0.

The whole reason there's even an issue is because UIGetScreenImage() is not part of the documented API, but Apple made a specific exception for using it. It's not like they are pulling current apps, but they are not allowing new submissions (or updates) that use the older technique.

There is some lobbying on behalf on a number of people to convince Apple to let app developers use the old technique for iOS 3.x only, so send an email to developer relations if you want to use it.

like image 36
Kendall Helmstetter Gelner Avatar answered Nov 15 '22 13:11

Kendall Helmstetter Gelner


Not possible from a documented api, but possible. Find the "PLCameraView" view in the camera's subviews, then call

CGImageRef img = (CGImageRef)[foundCameraView imageRef];

This will return a reference to the image that camera holds.

like image 137
Sophtware Avatar answered Nov 15 '22 12:11

Sophtware