我正在尝试从相机中获取图像文件名。我看过许多关于使用UIImagePickerControllerReferenceURL或UIImagePickerControllerMediaURL检索文件名的帖子,但这只会得到类似于://asset/asset.JPG?id = D1D715A8-6956-49FF-AF07-CE60FE93AE32& etc = JPG的文件名。我相信这是因为图像尚未保存,因此像img0001.jpg这样的名称不可用。
有谁知道如何获取文件名?我在起诉我需要在UIImageWriteToSavedPhotosAlbum之后做这个,但我似乎无法弄明白。
我已经多次看到这个问题了,但似乎没有人真的'回答它,他们只是总是从选择器中选择的图像中提供文件名而不是来自相机。
感谢您的帮助
**更新:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
{
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
NSURL *refURL = [info valueForKey:UIImagePickerControllerMediaURL];
// define the block to call when we get the asset based on the url (below)
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 (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
}
}
}
我上面的代码,但是当记录imageRep文件名时,它为空。