IOS sandbox image saving and reading instance


Examples are as follows:

//Save picture
-(void)saveImageDocuments:(UIImage *)image{
  //Get the picture
  UIImage *imagesave = image;
  NSString *path_sandox = NSHomeDirectory();
  //Set the storage path of an image
  NSString *imagePath = [path_sandox stringByAppendingString:@"/Documents/test.png"];
  //Save the image directly to the specified path (at the same time, the image path should be saved, which can be used to retrieve it next time)
  [UIImagePNGRepresentation(imagesave) writeToFile:imagePath atomically:YES];
//Read and store in album 
-(UIImage *)getDocumentImage{
  //Read sandbox path image
  NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.png",NSHomeDirectory(),@"test"];
  //Get the sandbox path picture
  UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3];
  //Photo album
  UIImageWriteToSavedPhotosAlbum(imgFromUrl3, self, nil, nil);
  return imgFromUrl3;

The above example of saving and reading IOS sandbox image is the whole content shared by Xiaobian. I hope I can give you a reference, and I hope you can support developeppaer more.