简体   繁体   中英

UIImagePickerController on Subview and Show Photo on UIImageView

I use UIImagePickerController on a subview (280x240). I use this code:

imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeAuto];
[imagePicker setShowsCameraControls:NO];
[imagePicker viewWillAppear:YES]; // trickery to make it show
[imagePicker viewDidAppear:YES];

[self.borderView addSubview:imagePicker.view]; //borderView size is 280x240

I am taking image picker original image and I want to take only displayed area on subview (borderView). How can I do?

try this.
 if ([UIImagePickerController     isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    imagePicker = [[MyImagePickerController alloc]init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.showsCameraControls=YES;
    [self presentViewController:imagePicker animated:YES completion:^{
        NSLog(@"Completed");
    }];

and then call delegate method of UIImagePickerController

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
capturedPicImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[capturedPicImageView sizeToFit];
capturedPicImageView.contentMode = UIViewContentModeScaleAspectFill;
capturedPicImageView.image = [self resizeAndStoreImages:capturedPicImageView.image];
UIImageWriteToSavedPhotosAlbum(capturedPicImageView.image, nil, nil, nil);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM