我有一个UI图像,我想找到它的路径。我怎么想这样做?
UIIImage *image ; // I have saved an image here
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [documentsPath stringByAppendingPathComponent: ????????? ]; // How to get the image from UIImage ?
答案 0 :(得分:0)
我告诉你问题的解决方案
STEP 1: If you have the image in Bundle,just follow the below code
NSString *stringImagePath = [[NSBundle mainBundle] pathForResource:@"Your_Image_Name" ofType:@"jpg"]; // or ofType:@"png", etc.
STEP 2: If you have image in particular place,just do the following code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
@"yourimage.png" ]; //or yourimage.jpg
NSLog(@"The image path is-%@",path);
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];