如何让这是iphone图库图片的路径(how to get the path of the imag

2019-08-04 00:55发布

我需要上传从iphone库中的图像,但我没有得到摄取的图像的路径 (使用图片选择器

在图片选择器的委托方法我在做以下

- (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,但我不能上传的文件,很可能这是我走的路径不正确。

任何人可以帮助我,我怎么能使用图像拾取采取摄取的图像的实际路径

Answer 1:

也许它会为û有帮助

[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];


Answer 2:

将您的图像中NSData然后上传这个NSData

您在NSData的图像

NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);

或者,你可以转换yourImage在NSData使用

NSData *dataImage = UIImagePNGRepresentation(yourImageView.image);

更多阅读的NSData类参考



文章来源: how to get the path of the image which is in iphone gallery