views:

167

answers:

2
+2  Q: 

iPhone Screenshots

Hi all,

I've been using UIGetScreenImage() to get a screenshot of a UIImagePickerController. Basically I use the camera overlay and then when I take the screenshot, I have the image that the camera preview had been showing and my overlay on there too, which is exactly what I need.

Now UIGetScreenImage() has been banned, I've not been able to find a way to do this. It just shows black for the camera.

Edit: all of my other views are showing absolutely fine, just not the actual camera preview. Any ideas??!?!?

Here's the code I am using at the moment.


UIGraphicsBeginImageContext(picker.view.bounds.size);
[picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
CGContextDrawImage(context, bounds, camView.CGImage);
UIImage* screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil); 
UIGraphicsEndImageContext();

Any ideas how I can get the overlay + the camera image?

Thanks!

A: 

This is slightly different than yours.

CGRect screenRect = [[UIScreen mainScreen] bounds];
        UIGraphicsBeginImageContext(screenRect.size);
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *sShot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageWriteToSavedPhotosAlbum (sShot, nil, nil, nil);

Does that work?

If not, you might want to try asking over at iphonedevsdk.com since they specialize in all things iPhone.

Ryan
Thanks, I gave that a go and it gave the same results (the view underneath the UIImagePickerController.I'll post a question over there too and see if anyone has done this before.
fdf33
A: 

Have them take a picture. Then overlay your image on top of it.

http://stackoverflow.com/questions/679245/create-a-uiimage-from-two-other-uiimages-on-the-iphone

Lou Franco
Thanks, that's a little too much though. Only need the image to be taken from the view itself. I might have to go down that route though.
fdf33
I think the reason that the API was removed is because its a security violation for you to get a screenshot without user intervention. There are ways to violate privacy that way, I think. Not sure if that's right, but otherwise, I don't have a good explanation of why it was removed with no alternative.
Lou Franco
Thanks for the explanation though! I'm sure there's a way to do it and stay within the guidelines, just annoying is all!
fdf33