Can I get the image name from photos on iPhone?

I use the image picker to select an image from the gallery on my iPhone. I need to save those images with the same name as in the gallery. I do not want to call him another after selecting an image. I tried to print a dictionary of information after selecting an image. It gives the image, url and path and type .. but how to get the actual image name of any idea. Below I get in didFinish

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"Selected image info: %@",info); } 

it prints

 Selected image info : ( { UIImagePickerControllerMediaType = "public.image"; UIImagePickerControllerOriginalImage = "<UIImage: 0x617d390>"; UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1000000089&ext=JPG"; } ) 

My question is to get the actual name from the above.

+4
source share
3 answers

Using the AssetsLibrary framework, you can get the referenceURL from the information dictionary and extract the asset. Something like that:

 NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL]; __block NSString *fileName = nil; ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease]; [library assetForURL:assetURL resultBlock:^(ALAsset *asset) { fileName = asset.defaultRepresentation.fileName; } failureBlock:nil]; 
+5
source

Images from the selected gallery do NOT have "names". You never give a name to the picture you just recorded from the camera, and even when you add images via iTunes, the original file names are deleted and replaced with the names of the files that iTunes understands for synchronization.

These file names are not intended for programmer access, as they may be replaced with other images in the future.

A good circle for this is to set the current date as file names, as well as save images selected from the gallery. You can save it in your documents or in the library directory and use the PList file to map images to their name.

Alternatively, you can also assign unique numbers as file names and access images using these values.

Although you mentioned that you do not want to assign new names, unfortunately this is the only way to do this.

+4
source

I don’t think they have a name. What I used in my application was to save them with NSDate (current date) as a name.

0
source

All Articles