【问题标题】:Saving changes of edited UIImage to same file将编辑后的 ​​UIImage 的更改保存到同一文件
【发布时间】:2017-02-06 12:52:12
【问题描述】:

所以这个对你来说应该很简单。 我无法将编辑后的 ​​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);

但还是一样。

【问题讨论】:

    标签: ios objective-c image uiimage


    【解决方案1】:

    自 iOS 9.0 起,Assets Library 框架已被弃用,我建议您使用 PHPhotoLibrary。 无论如何要将图像写入文件,您可以使用:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      相关资源
      最近更新 更多