2

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.

  • 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. –  Oct 13 '09 at 23:20
  • Have you got the solution yet? – Suhail Bhat Dec 12 '14 at 20:36

2 Answers2

1

theTabView.view.layer?

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • 1
    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. –  Oct 14 '09 at 06:24
-1

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!

k_o_r
  • 99
  • 1
  • 4
  • 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 Nov 23 '15 at 14:35