如何获得在iPhone画廊的图像的path
我需要从iPhone画廊上传图像,但我没有得到所选图像的path (使用图像select器 )
在图像select器委托方法,我正在做下面的事情
- (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); }
info字典包含以下关键值
{ UIImagePickerControllerMediaType = "public.image"; UIImagePickerControllerOriginalImage = "<UIImage: 0x16adc0>"; UIImagePickerControllerReferenceURL = "assets-library://asset/asset.PNG?id=1000000153&ext=PNG"; }
我使用的关键UIImagePickerControllerReferenceURL的值作为图像path上传到FTP,但我不能上传文件,可能是我采取的path是不正确的。
任何人都可以帮助我,我怎么能采取图像采集器采摘的图像的实际path
可能会对你有帮助
[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];
在NSData
转换你的图像,然后上传这个NSData
。
你的形象在NSData
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
或者你可以使用NSData
转换yourImage
NSData *dataImage = UIImagePNGRepresentation(yourImageView.image);
更多的阅读NSData类参考