gpt4 book ai didi

ios - Xcode/ios : How do you get name of image after letting user select one and displaying it?

转载 作者:行者123 更新时间:2023-12-01 18:53:17 25 4
gpt4 key购买 nike

我有代码可以让用户选择现有图像并让它在屏幕上的 UIView 中很好地显示。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
NSLog(@"image is%@",chosenImage);
[picker dismissViewControllerAnimated:YES completion:NULL];
}

如何获取文件名以将其保留以供将来引用? selectedImage 只是向您显示有关该文件的一堆元数据。

谢谢你。

最佳答案

如下所示,您无法从 UIImagePickerControllerDelegate 中获取所选图像的名称使用当前现有的 API。

这里有 UIImagePickerControllerDelegate 的可用 Editing Information Keys :

NSString *const UIImagePickerControllerMediaType;
NSString *const UIImagePickerControllerOriginalImage;
NSString *const UIImagePickerControllerEditedImage;
NSString *const UIImagePickerControllerCropRect;
NSString *const UIImagePickerControllerMediaURL;
NSString *const UIImagePickerControllerReferenceURL;
NSString *const UIImagePickerControllerMediaMetadata;

但是,您可能想使用 AssetsLibrary.framework 获取由 Photos 应用程序管理的图像的名称:
@import AssetsLibrary;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:info[UIImagePickerControllerReferenceURL]
resultBlock:^(ALAsset *fileAsset) {

NSLog(@"%@", [[fileAsset defaultRepresentation] filename]);

} failureBlock:nil];
}

关于ios - Xcode/ios : How do you get name of image after letting user select one and displaying it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29585182/

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