gpt4 book ai didi

ios - 如何获取所选图像的 'file' 的名称

转载 作者:行者123 更新时间:2023-11-29 03:16:38 25 4
gpt4 key购买 nike

我正在尝试获取使用此代码选择的图像的文件名:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
img = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.imgFoto setImage:img];

NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
NSLog(@"image name is %@", imageName);

[self dismissViewControllerAnimated:YES completion:NULL];
}

但我看到的是:

enter image description here

我的意思是,我不应该像 IMG_00001.jpegIMG_00002.jpeg 等等?

问候。

最佳答案

按以下代码行使用 AssetsLibrary

#import <AssetsLibrary/AssetsLibrary.h>

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

NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
};

// get the asset library and fetch the asset based on the ref url
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];

关于ios - 如何获取所选图像的 'file' 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com