Can I programmatically turn on the camera flash on a new iPhone 4 device, before taking a picture with -takePicture
?
I'm developing a photo taking app for iOS 4 and want to power on the flash light before the user takes a picture, so they can see the effect of the flash in advance.
The problem seems to be that for the flash light to stay on, you'll need to set the torchMode
on and this is only possible in 'video mode' (UIImagePickerControllerCameraCaptureModeVideo
), while you can only ask the UIImagePickerController
to takePicture
when it is on 'photo mode' (UIImagePickerControllerCameraCaptureModePhoto
).
So, the following works, but only shows the flash light when taking a picture:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:@"public.image", nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
And this also works (shows the torch the whole time), but then I cannot take a picture.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls开发者_如何学JAVA = NO;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
[self presentModalViewController:picker animated:YES];
When I try the toggleTorch
code found here: Turn on torch/flash on iPhone there seems to not be any live video feed in the UIImagePickerController
.
Are these UIImagePickerController
and AVCaptureSession
compatible with each other? or are you supposed to choose for either one or the other?
And does anybody know a workaround to get both the flash mode on (or torchMode
) and to be able to takePicture
?
Have a look at the WWDC 2010 sessions (specifically 409) where they go into functionality like the one you're looking for.
Essentially you need to move away from UIImagePickerController if you're looking to perform these custom camera functions and move towards AVFoundation classes.
精彩评论