how to get the path of the image which is in iphone gallery

北战南征 提交于 2019-12-09 06:49:50

问题


i need to upload a image from iphone gallery ,but i am not getting the path of the picked image (using image picker)

in the image picker delegate method i am doing the following

- (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);

}

and the info dictionary contains following key values

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

i used the value for key UIImagePickerControllerReferenceURL as the image path to upload it to FTP but i couldnt upload the file, probably the path which i taking is incorrect.

can anybody help me out how can i take the actual path of the picked image using image picker


回答1:


May be it will helpful for u

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



回答2:


Convert your image in NSData and then Upload this NSData.

Your image in NSData

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

Or you can convert yourImage in NSData using

NSData *dataImage = UIImagePNGRepresentation(yourImageView.image);

For more read NSData Class Reference



来源:https://stackoverflow.com/questions/13854723/how-to-get-the-path-of-the-image-which-is-in-iphone-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!