拾取图像的名称xcode

Ass*_*sin 1 xcode objective-c uiimagepickercontroller ios

我想获取从库中挑选或最近点击的图像的名称 -

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        AppDelegate *del = [[UIApplication sharedApplication]delegate];
        [self dismissModalViewControllerAnimated:YES];
        image = [info objectForKey:UIImagePickerControllerOriginalImage];

        NSLog(@"imagekbgfg=====>%@",image);
        [self.imageView setImage:image];

        imgName = [info objectForKey:UIImagePickerControllerOriginalImage];

        del.mainImgName = imgName;
        del.imageData = UIImageJPEGRepresentation(image, 1.0);
        del.imageApp = image;
    }

    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
       image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

sun*_*ppy 6

使用下面的代码,您将获得如下路径:assets-library://asset/asset.JPG?id=79450962-C0FD-484C-808B-83E045F40972&ext=JPG当您从相册中挑选图像时.此路径有效.它包含资产ID和资产类型.

// Firstly get the picked image's file URL.
NSURL *imageFileURL = [info objectForKey:UIImagePickerControllerReferenceURL];

// Then get the file name.
NSString *imageName = [imageFileURL lastPathComponent];
NSLog(@"image name is %@", imageName);
Run Code Online (Sandbox Code Playgroud)

如果你想使用你使用的路径再次选择图像用户UIImagePickerController.(这里可能你想保存路径,这样你就可以回读那个图像,而不会要求用户再次选择那个图像)你将需要ALAssetsLibrary另外你不要需要它.

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *returnValue = nil;
[library assetForURL:imageFileURL resultBlock:^(ALAsset *asset) {
    returnValue = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
} failureBlock:^(NSError *error) {
    NSLog(@"error : %@", error);
}];
Run Code Online (Sandbox Code Playgroud)