IPhone takes screenshot with UIImagePickerController View - always black if app is TAB
Attempting to take a screenshot when the user is in camera mode and the custom pictures take the picture. I have an application with multiple tabs. In one of them, the user launches the camera. I am using CameraOverViewController to create a custom button to take a snapshot [picker takePicture]. When this picture is taken, I also take the picture using standard methods. This all works fine in a test app without tabs, as soon as I enter tabs it just returns a black square. I understand that it will most likely do the correct view, I cannot 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.
thank.
+2
Jot
source
to share
2 answers
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 get your shot and saved in your photo album. ciao!
-1
source to share