Source
Source

Reputation: 109

How to get the path of an image?

How can I get the path or directory of the PHAsset images?

I came across an answer here written by @diegomen but when I try it like selectedAssets[0].PHAsset.getURL() it asks for a parameter but @diegomen said it doesn't require a parameter from the comments.

Am I applying it wrong?

Or is there other way of getting the images path from PHAsset?

NOTE: I found another solution here by @Clay but it doesn't seem to be the good practice to do it.

Upvotes: 0

Views: 1255

Answers (2)

khusboo suhasini
khusboo suhasini

Reputation: 303

If you have already store image in your local file path and you want to retrive the image file Path from your PHAsset image address then use this function:

[asset requestContentEditingInputWithOptions:[PHContentEditingInputRequestOptions new] completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    NSURL *imageURL = contentEditingInput.fullSizeImageURL;
    }];

asset=PHAsset *asset

Upvotes: 2

Pavlo Boiko
Pavlo Boiko

Reputation: 583

You should store image to local file. After that you will have file url.

NSData *imageData = UIImagePNGRepresentation(newImage);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",@"cached"]];
[imageData writeToFile:imagePath atomically:NO];

Upvotes: -1

Related Questions