将图像保存到文档文件夹

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将图像保存到文档文件夹相关的知识,希望对你有一定的参考价值。

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

以上是关于将图像保存到文档文件夹的主要内容,如果未能解决你的问题,请参考以下文章