How to get the path to the image that is in the iphone gallery

I need to download an image from the iphone gallery, but I do not get the path of the selected image (using the image picker )

in the delegate method of the image picker i do 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 information dictionary contains the following key values

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

I used the value for the UIImagePickerControllerReferenceURL key as the image path for uploading it to FTP, but I could not upload the file, maybe the path that I accept is incorrect.

can someone help me how can I take the actual path of the selected image using the image picker

+4
source share
2 answers

Maybe it will be useful 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]; 
+12
source

Convert the image to NSData and then Download it NSData .

Your image in NSData p>

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

Or you can convert yourImage to NSData using

 NSData *dataImage = UIImagePNGRepresentation(yourImageView.image); 

Read the NSData class reference in more detail.

+1
source

All Articles