我有一个绘图应用程序,其中有一个 UIImageView 作为“绘图层”。您在其下方有另一个 UIImageView,即“图像层”,其中包含您正在绘制的图像。我喜欢这种分离。但是,我希望用户能够“保存并通过电子邮件发送”他们在图像顶部制作的绘图作为一个统一的图像。我该怎么做呢?
user748176
问问题
738 次
1 回答
4
您的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 设置中。
于 2012-09-26T13:44:42.350 回答