我有一个绘图应用程序,其中有一个 UIImageView 充当“绘图层”。它下面有另一个 UIImageView,它是“图像层”,包含您正在绘制的图像。我喜欢这种分离。但是,我希望用户能够将他们在图像之上制作的绘图作为一张统一图像“保存并通过电子邮件发送”。我该怎么做?
最佳答案
您的 UIImageView
实例必须是 UIView
层次结构的一部分,因此您需要做的就是将包含 UIView
的顶部绘制到上下文中
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[container.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *fimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
或者如果这给您带来麻烦,请将两个图像连续绘制到上下文中
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[image1.layer renderInContext:UIGraphicsGetCurrentContext()];
[image2.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *fimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
从那里您可以在您选择的位置写入数据
NSData *data = UIImagePNGRepresentation(fimage);
将该数据传递到 MailComposer 设置中。
关于ios - 如何将 "combine"两个 UIImageView 合并到一张图像中?喜欢 Photoshop 图层合并吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12602118/