如何获取iphone gallery中图像的路径
我需要从iphone gallery上传图像,但我无法获取所选图像的路径(使用图像选择器) 在图像选择器委托方法中,我执行以下操作如何获取iphone gallery中图像的路径,iphone,objective-c,ios,path,uiimagepickercontroller,Iphone,Objective C,Ios,Path,Uiimagepickercontroller,我需要从iphone gallery上传图像,但我无法获取所选图像的路径(使用图像选择器) 在图像选择器委托方法中,我执行以下操作 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; imageView.
- (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";
}
{
UIImagePickerControllerMediaType=“public.image”;
UIImagePickerControllerOriginalImage=“”;
UIImagePickerControllerReferenceURL=“资产-library://asset/asset.PNG?id=1000000153&ext=PNG";
}
我使用键UIImagePickerControllerReferenceURL的值作为图像路径将其上载到FTP,但我无法上载文件,可能我采用的路径不正确
有人能帮我确定如何使用图像采集器获取拾取图像的实际路径在
NSData
中转换图像,然后上载此NSData
您在NSData中的图像
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
或者,您可以在NSData
中使用
NSData *dataImage = UIImagePNGRepresentation(yourImageView.image);
如需了解更多信息,请阅读,这可能对您有所帮助
[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];
Thanx表示您的答案,但数据正在返回null NSData*data=[[NSData alloc]initWithContentsOfURL:[info valueForKey:UIImagePickerControllerReferenceURL];我也用这个在FTP服务器上发送图像。它非常适合me@Sudha有没有办法获取路径而不将其保存在文档目录中,因为它已保存在中somewhere@sudha我无法将图像发送到ftp服务器,请帮助me@RamaniAshish看看这些。。。有没有不复制原始文件的方法?