views:

1129

answers:

2

Hello,

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.

+1  A: 

theTabView.view.layer?

Noah Witherspoon
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.
+1  A: 

I can't get the sample code to work, even without the Tabs. I can't really help until I can at least get THAT to work

iSkythe
What image is returned for you? Is it black or a pic of the interface?
Well it won't compile as you have it, I have to change self.picker.view.layer to picker.view.layer, then, I use UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);When I check it, it is a picture of the interface only. No camera feed. I don't have any tabs.
iSkythe