2016-09-28 3 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

Assets Library 프레임 워크는 iOS 9.0부터 사용되지 않으므로 PHPhotoLibrary를 사용하시기 바랍니다. 어쨌든 파일에 이미지를 작성하는 다음을 사용할 수 있습니다

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

또는

[imageData writeToFile:path options:NSDataWritingAtomic error:&writeError]; 
관련 문제