【发布时间】:2015-06-16 18:13:10
【问题描述】:
我有一个具有UIImage 和DrawView 作为子视图的视图。绘制视图响应触摸并创建一个UIBezierPath 用于在图像上绘制。当用户接受他们的更改时,我需要将基础UIImage 和任何UIBezierPath 创建到一个UIImage 中。
【问题讨论】:
标签: uiimageview uiimage core-graphics uibezierpath
我有一个具有UIImage 和DrawView 作为子视图的视图。绘制视图响应触摸并创建一个UIBezierPath 用于在图像上绘制。当用户接受他们的更改时,我需要将基础UIImage 和任何UIBezierPath 创建到一个UIImage 中。
【问题讨论】:
标签: uiimageview uiimage core-graphics uibezierpath
将UIBazierPath 设为DrawView 的公共属性,并在用户从DrawView 中绘图时不断更新它。当用户点击接受按钮时,使用以下代码在上下文中简单地创建 UIImageContext 和 draw,sourceImage 和 bezierPath。最后在resultImage 中获取上下文中绘制的任何内容。
UIBezierPath *path = drawView.Path // Your Bezier Path in DrawView
UIImage *sourceImage = sourceImageView.image; // Your Source Image from ImageView.
UIImage *resultImage = nil;
UIGraphicsBeginImageContext(sourceImage.size);
[sourceImage drawInRect:(CGRect){CGPointZero, sourceImage.size}];
[path stroke]; //Fill or Stroke path as you need.
[path fill];
resultImage = UIGraphicsGetImageFromCurrentImageContext(); //taking the merged result from context, in a new Image. This is your required image.
UIGraphicsEndImageContext();
//Use resultImage as you want.
【讨论】: