【发布时间】:2012-09-26 12:49:48
【问题描述】:
我有一个绘图应用程序,其中有一个 UIImageView 作为“绘图层”。在它下面还有另一个 UIImageView,它是“图像层”,包含您正在绘制的图像。我喜欢这种分离。但是,我希望用户能够“保存并通过电子邮件发送”他们在图像顶部制作的绘图作为一个统一的图像。我该怎么做?
【问题讨论】:
标签: ios uiimageview drawing
我有一个绘图应用程序,其中有一个 UIImageView 作为“绘图层”。在它下面还有另一个 UIImageView,它是“图像层”,包含您正在绘制的图像。我喜欢这种分离。但是,我希望用户能够“保存并通过电子邮件发送”他们在图像顶部制作的绘图作为一个统一的图像。我该怎么做?
【问题讨论】:
标签: ios uiimageview drawing
您的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 设置中。
【讨论】: