3

是否可以拍摄嵌入在应用程序中的视频并将其保存到相机胶卷中?如果是这样,怎么做?它是同一个 UIWriteImage 的东西吗?

4

2 回答 2

11

假设您已经知道如何保存图像,您可以尝试此代码:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
       //Save the video
       NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];
       UISaveVideoAtPathToSavedPhotosAlbum([movieUrl relativePath], self,@selector(movie:didFinishSavingWithError:contextInfo:), nil);
    }
}

或者你可以试试:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  if([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
    NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error){
        if(error) {
            NSLog(@"CameraViewController: Error on saving movie : %@ {imagePickerController}", error);
        }
        else {
            NSLog(@"URL: %@", assetURL);
        }
    }];
  }
}
于 2012-05-03T08:41:15.917 回答
3

对于 iOS 8 及更高版本,请使用PHPhotoLibraryALAssetsLibrary已弃用。

包括:

@import PhotosUI;

然后用它来保存你的电影:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
 {
     [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:<%Your Movie URL%>];
 }
                                  completionHandler:^(BOOL success, NSError *error)
 {
     if (success) {
         NSLog(@"Movie saved to camera roll.");
     }
     else {
         NSLog(@"Could not save movie to camera roll. Error: %@", error);
     }
 }];
于 2016-05-16T18:23:11.830 回答