2016-09-28 84 views
0

所以这个对你来说应该很简单。 我很难保存编辑UIImage(只是水平翻转)到同一个文件。相反,它会创建一个新的。将编辑好的UIImage文件保存到同一个文件

代码:

// Get current photo 
    id<MWPhoto> currentPhoto = [self photoAtIndex:_currentPageIndex]; 

    // Get current image object from photo 
    UIImage *currentImage = [self imageForPhoto:(currentPhoto)]; 

    // Mirror it 
    currentImage = [UIImage imageWithCGImage:currentImage.CGImage 
                scale:currentImage.scale 
               orientation:UIImageOrientationUpMirrored]; 

    // Get NSData from image 
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 1); 

    // Create ALAsssetsLibrary to save data to photos 
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    [library writeImageDataToSavedPhotosAlbum:imageData metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) { 
     if (error != nil) { 
      NSLog(@"There was an error saving image"); 
     } else { 
      NSLog(@"Image should be saved"); 
      } 
    }]; 

任何想法,我做错了什么?

UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);

,但还是一样也试过。

回答

1

资产库框架从iOS 9.0开始已弃用,我建议你使用PHPhotoLibrary。 反正写的图像文件,你可以使用:

[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES]; 

[imageData writeToFile:path options:NSDataWritingAtomic error:&writeError];