如何获取UIImage的完整文件路径



我有一个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 ?

我告诉你问题的解决方案

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

最新更新