Posted By

rabc on 07/20/10


Tagged

image iphone documents


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

umang_nine
bobbym245
rvachere
cnathan
Rakesh


Save image to Documents folder


 / Published in: Objective C
 

  1. NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
  2. stringByAppendingPathComponent:@"images"];
  3.  
  4. // save the file
  5. NSString *imagePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",
  6. [imageName stringByReplacingOccurrencesOfString:@" " withString:@"_"]]];
  7. if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
  8. // delete if exist
  9. [[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
  10. }
  11.  
  12. NSData *imageDate = [NSData dataWithData:UIImagePNGRepresentation(image)];
  13.  
  14. [imageDate writeToFile: imagePath atomically: YES];

Report this snippet  

You need to login to post a comment.