0

I have a UI Image and i want to find the path of it. How am i suppose to do it ?

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 ?
Illep
  • 16,375
  • 46
  • 171
  • 302

1 Answers1

0

I tell you the solution for your question

  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]; 
user3182143
  • 9,459
  • 3
  • 32
  • 39