iPhone Take Screenshot of UIImagePickerController View - Always black if TAB app

Attempting to take a screenshot when the user is in Camera mode and user hits take picture. I have an application with several tabs. In one of them the user launches the Camera. I use CameraOverViewController to make a custom button to take a picture [picker takePicture]. When this picture is taken I also a screen shot of the picture using standard methods. This all works fine in a test app with no tabs, as soon as I introduce tabs it just returns a black square. I realize its likely to do with getting the right VIEW, I can't figure out which view to get.

    // the view loaded in the tab view 
@interface CameraTestViewController : UIViewController |UIImagePickerControllerDelegate, UINavigationControllerDelegate|

UIImagePickerController *picker

.m
- (void) setUpCamera : (id) sender {
picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 
picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
picker.allowsEditing = NO; 
picker.showsCameraControls = NO;
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_SCALAR, CAMERA_SCALAR);  

CameraOverViewController *createOverlay = [[CameraOverViewController alloc] initWithNibName:@"CameraOverViewController" bundle:nil];    
[createOverlay mainView:self];              
[picker setCameraOverlayView:createOverlay.view];

[self presentModalViewController:picker animated:YES];      
[picker release];

}

- (void) snapThePicture {
    [picker takePicture];
}

// TAKE SCREEN SHOT AS WELL. WORKS WITH NO TABS
- (void)imagePickerController:(UIImagePickerController *)pickerHere didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // tried many, many things. self.view.layer, etc
    CGRect screenRect  = CGRectMake(0, 0, 320, 480);
    UIGraphicsBeginImageContext(screenRect.size);
    [self.picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];

        // UIIMAGE ALWAYS A BLACK RECTANGLE OF RIGHT SIZE. WOULD WORK IF NOT IN TAB VIEW

         UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

Any help is appreciated.

thanks.

13.10.2009 22:15:20
Should mention if I use 'self.view.layer' it returns a picture of the interface, not of the picture. I don't dismiss the view until after trying to get the screenshot. And it does work when its not in a tab view.
Jot 13.10.2009 23:20:01
Have you got the solution yet?
Suhail Bhat 12.12.2014 20:36:51
2 ОТВЕТА

theTabView.view.layer?

1
14.10.2009 05:21:33
Nope. That still just takes a picture of the interface, not of what the camera is looking at. If we can solve this we will get super quick scaled version of the camera image, a current performance problem area with coding for the iPhone.
Jot 14.10.2009 06:24:54

maybe this can help you as it worked for me:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {    

UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage ];
NSData *mydata= UIImageJPEGRepresentation(img , 1);
UIImageWriteToSavedPhotosAlbum(img, self, nil, nil);

}

with this basically you will have your snapshot taken and saved to your PhotoAlbum. ciao!

-1
22.11.2010 16:19:14
How is that a solution? That's the entire image... The OP is clearly asking for a solution that allows him to crop the image (CGRect screenRect = CGRectMake(0, 0, 320, 480); UIGraphicsBeginImageContext(screenRect.size);)
Kevin 23.11.2015 14:35:06