How do I get the original filename of the image selected by UIImagePickerController?
I have implemented a delegate method and can access the selected UIImage like:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *pickedImage = [info valueForKey:UIImagePickerControllerOriginalImage];
I want to store it in a directory, but I need the filename. So instead of just choosing an arbitrary filename, it makes sense to choose the same filename as the image.
Is there a way to extract it from this information dictionary?
+2
source to share
2 answers
- Use the ALA Assets library infrastructure
-
Use below code
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
source to share