选择的图像 xcode 的名称 [英] name of the picked image xcode

查看:21
本文介绍了选择的图像 xcode 的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get the name of the image picked from the library or newly clicked in -

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

我正在使用此代码:

-(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];
    }
}

我该怎么做?

推荐答案

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

Using the code bellow you will get path like:assets-library://asset/asset.JPG?id=79450962-C0FD-484C-808B-83E045F40972&ext=JPG when your picking image from photo album. This path is valid. It contains the asset ID and asset type.

// 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);

如果您想使用您使用 UIImagePickerController 获得的路径再次选择图像用户.(这里也许您想保存路径,以便您可以在不要求用户选择的情况下读取该图像再次图像)您将需要 ALAssetsLibrary 否则您不需要它.

If you want to get image user picked again using the path you get using UIImagePickerController.(Here maybe you want to save the path so that you can read that image back without asking user to pick that image again) You will need the ALAssetsLibrary otherwise you don't need it.

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);
}];

这篇关于选择的图像 xcode 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆