如何为 iOS 开发保存合成或修改后的图像?
我向图像添加了叠加层(从相册中选择),但无法保存合成图像,以下代码仅保存原始图像。有人建议修改图像对象以添加图像吗?
#pragma mark -
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
overlay.alpha = 0.6; // Customize the opacity of the top image.
[imageView addSubview:overlay];
CGContextRef context = UIGraphicsGetCurrentContext();
//UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image
UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), context);
[picker dismissModalViewControllerAnimated:YES];
}
I added an overlay to my image (selected from photo album) and I can't save the composite, the following code only saves the original image. Any one out have a suggestion to modify the image object to have the added image?
#pragma mark -
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
overlay.alpha = 0.6; // Customize the opacity of the top image.
[imageView addSubview:overlay];
CGContextRef context = UIGraphicsGetCurrentContext();
//UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image
UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), context);
[picker dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIImageWriteToSavedPhotosAlbum(imageView.image.layer, self)
UIImageWriteToSavedPhotosAlbum(imageView.image.layer, self)
谢谢@拉胡尔维亚斯。我没有尝试你的建议,但我仍然感谢你的意见。最终在 Apple Dev 论坛的帮助下解决了这个问题。
这个问题的答案是,因为它对我有用:
Thank you @Rahul Vyas. I didn't try your suggestion, but I still appreciate your input. Ended up getting this issue resolved from help from the Apple Dev forums.
The answer to this problem is, as it worked for me: