我有一个绘图应用程序,你有一个UIImageView作为“绘图层”。你下面有另一个UIImageView,它是“图像层”,包含你正在绘制的图像。我喜欢这种分离。但是,我希望用户能够将他们在图像上制作的绘图“保存并通过电子邮件发送”为一个统一的图像。我该怎么做?
答案 0 :(得分: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设置。