所以这个对你来说应该很简单。 我在编辑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);
但仍然相同。
答案 0 :(得分:1)
从iOS 9.0开始,不推荐使用Assets Library框架,我建议您使用PHPhotoLibrary。 无论如何要将图像写入文件,您可以使用:
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
或
[imageData writeToFile:path options:NSDataWritingAtomic error:&writeError];