1

使用 uiimagepicker 控制器时出现上述错误。这是我的代码:

- (BOOL) startCameraControllerFromViewController:(UIViewController *)controller andisImageFromCamera:(BOOL)isCameraCapture {


    if(self.picker == nil) {
        /**< instansiate UIImagePickerController object */
        self.picker = [[UIImagePickerController alloc] init];;
    }
    /**< Check isSourceTypeAvailable for possible sources (camera and     photolibrary) */
    if (([UIImagePickerController isSourceTypeAvailable:    UIImagePickerControllerSourceTypeCamera] == NO) || ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO))
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Oops!! This feature is not supported on your device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alertView show];

        return NO;
    }

    self.picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    self.picker.delegate = self;
    self.picker.mediaTypes =[NSArray arrayWithObjects: (NSString *) kUTTypeMovie, (NSString *) kUTTypeImage, nil];
    self.picker.videoMaximumDuration = MAX_VIDEO_DURATION;
    self.picker.allowsEditing = YES;
    self.picker.videoQuality =    UIImagePickerControllerQualityTypeMedium;


    /**< if editing is required*/
    [self presentViewController:self.picker animated:YES completion:^{

    }];

    return YES;

}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

    NSURL *videoURL = [info valueForKey:UIImagePickerControllerMediaURL];
    NSString *pathToVideo = [videoURL path];

    if(![pathToVideo isEqualToString:@""] && pathToVideo != nil) {
        BOOL okToSaveVideo =    UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(pathToVideo);
        if (okToSaveVideo) {
            //UISaveVideoAtPathToSavedPhotosAlbum(pathToVideo, self,   @selector(video:didFinishSavingWithError:contextInfo:), NULL);
        }
    }
    if ([info[UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]) {
        // video
        isVideoFromGallery = YES;
        isMediaTypeVideo = YES;
        [self videoCaptureSaveAction:videoURL andMediaInfo:info];
    }
    else{

        isMediaTypeVideo = NO;
        UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
        self.previewImage = chosenImage;
        self.capturedImageData = UIImageJPEGRepresentation(chosenImage, 90);
        [self performSegueWithIdentifier:@"previewCapture" sender:self];
    }
}

选择视频正在工作。但是当我选择图像时,我遇到了错误:[Generic] 创建具有未知类型的图像格式是错误的。我已阅读有关此错误的其他帖子,更改了委托方法,但仍然无法正常工作。请帮忙。

4

0 回答 0