gpt4 book ai didi

iphone - 如何获取iphone图库中图像的路径

转载 作者:可可西里 更新时间:2023-11-01 05:02:54 24 4
gpt4 key购买 nike

我需要从 iphone 画廊上传图片,但我没有得到所选图片的路径(使用图片选择器)

在图像选择器委托(delegate)方法中,我正在执行以下操作

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

NSString *strImagePath = [info valueForKey:UIImagePickerControllerReferenceURL];
NSString *strImagePath1 = [info valueForKey:UIImagePickerControllerMediaURL];
NSLog(@"%@",strImagePath);
NSLog(@"%@",strImagePath1);
NSLog(@"%@",info);

}

信息字典包含以下键值

{
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x16adc0>";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=1000000153&ext=PNG";
}

我使用键 UIImagePickerControllerReferenceURL 的值作为图像路径将其上传到 FTP 但我无法上传文件,可能是我采用的路径不正确。

任何人都可以帮助我如何使用图像选择器获取所选图像的实际路径

最佳答案

可能对你有帮助

[picker dismissModalViewControllerAnimated:YES];
imageView.image= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *webData = UIImagePNGRepresentation(imageView.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:png];
[webData writeToFile:localFilePath atomically:YES];
NSLog(@"localFilePath.%@",localFilePath);

UIImage *image = [UIImage imageWithContentsOfFile:localFilePath];

关于iphone - 如何获取iphone图库中图像的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854723/

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