gpt4 book ai didi

ios - 将已编辑的 UIImage 的更改保存到同一文件

转载 作者:行者123 更新时间:2023-11-29 00:39:57 25 4
gpt4 key购买 nike

所以这个对你来说应该很简单。我在将编辑后的 ​​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 9.0 开始,资源库框架已被弃用,我建议您使用 PHPhotoLibrary。无论如何要将图像写入文件,您可以使用:

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

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

关于ios - 将已编辑的 UIImage 的更改保存到同一文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39749240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com