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

前端 未结 2 1241
谎友^
谎友^ 2021-02-10 23:42

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 picke

相关标签:
2条回答
  • 2021-02-11 00:20

    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];
    
    0 讨论(0)
  • 2021-02-11 00:21

    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

    0 讨论(0)
提交回复
热议问题