5

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.

4 Answers 4

4

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.

1
  • Will Apple reject an app that does this?
    – user142019
    Jun 3, 2011 at 14:50
2

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.

0

This isn't possible unfortunately. For performance the iPhone uses some form of direct rendering to draw the camera preview directly onto the screen instead of as part of a UIView surface. As such when you "capture" the camera view you will only get the UIView elements, not the preview image.

(FWIW this is similar to the reasons why its difficult to screengrab some movie software on Windows/Mac)

3
  • I think it should be possible, since there are apps in the AppStore that clearly take screenshots of the camera preview window (e.g. QuadCam). If you call UIGetScreenImage() you actually do get an image of the camera preview - but this is a private API function and shouldn't be used.
    – 3n.
    Mar 2, 2009 at 6:06
  • Yes, UIGetScreenImage grabs the current framebuffer. renderInContext draws the view hierarchy of the specified view into a context. These are conceptually different things. Mar 2, 2009 at 6:50
  • Yes, I understand that. The reason I'm asking is someone by the name "Rolando" has posted that he has a third way to save the camera preview as an image, but claims he can't divulge the information due to an NDA. blog.airsource.co.uk/index.php/2008/11/11/…
    – 3n.
    Mar 3, 2009 at 6:31
0

You could try AVCaptureVideoPreviewLayer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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