How to obtain the original file name of the image picked by UIImagePickerController?

前端 未结 2 1036
清酒与你
清酒与你 2021-01-21 20:17

I\'ve implemented the delegate method and can get access to the picked UIImage, like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFin         


        
相关标签:
2条回答
  • 2021-01-21 20:52

    You could use the UIImagePickerControllerReferenceURL value of the info dictionary instead of the UIImagePickerControllerOriginalImage. This should give you the URL to the original media item.

    This would return you a NSURL object which you then can use to build your new filename from.

    0 讨论(0)
  • 2021-01-21 20:58
    • Use ALA Assets library framework
    • Use the code below

      
          ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
          UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
          [library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error )
          {
             [library assetForURL:assetURL resultBlock:^(ALAsset *asset )
             {
               ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
               {
                   ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
                   NSLog(@"reference image filename picking from camera: %@", [imageRep filename]);
               };
               ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
               [assetslibrary assetForURL:assetURL resultBlock:resultblock failureBlock:nil];
             }
             failureBlock:^(NSError *error )
             {
                 NSLog(@"Error loading asset");
             }];
          }];
      
      
      imageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
      imageView.contentMode = UIViewContentModeScaleAspectFit;
      
    0 讨论(0)
提交回复
热议问题