现在你想在风景和肖像模式下拍照?如果是这样,下面是我的代码,但这里 Iget preview in portrait mode oly ,如果你想在横向模式下你必须使用自定义方法创建 UIImagePickerViewController 因为预览只会在纵向模式下获得。
但是你可以用你想要的任何一种模式拍照,看看下面的这段代码可能会对你有所帮助..
-(void)cameraAction
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
imagePicker.allowsEditing = NO;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
NSLog(@"called");
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing the camera" message:@"Camera did not respond" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[picker release];
[self dismissModalViewControllerAnimated:NO];
editImageView=[[EditImageViewController alloc] initWithNibName:@"EditImageViewController" bundle:[NSBundle mainBundle]];
editImageView.delegate=self;
[self presentModalViewController:editImageView animated:YES];
[editImageView.imgView setImage:image];
}