2016-09-28 87 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];