ios - 在 UIView 中绘制触摸点会在边界上产生模糊的绘制效果

标签 ios objective-c uiview core-graphics calayer

解决我的最后一个问题:Draw/Paint like sketch color inside a bezier path in UIView ,我拍摄了一张充满所选颜色的精确图像(路径)。然后,为了在 UIView 中绘制它,我采用了上下文颜色:

lineColor=[UIColor colorWithPatternImage:img];

在 drawrect 中:

CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
CGPoint mid2 = midPoint(currentPoint, previousPoint1);
[curImage drawInRect:CGRectZero];
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, 
                             previousPoint1.x, 
                             previousPoint1.y, 
                             mid2.x, 
                             mid2.y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context,lineColor.CGColor);
CGContextSetShouldAntialias(context, YES);
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetFlatness(context,0.5);
CGContextSetAlpha(context, 1.0);
CGContextStrokePath(context);

它准确地绘制在 View 路径上,但在边界上颜色像融化效果一样消失。

必须填充颜色的源图像: Image to be filled with color

用作 colorWithPatternImage (img) 的图像 enter image description here

在触摸上绘制后,结果图像: enter image description here

我在这里缺少什么来完美地填充它? 欢迎任何有关核心图形的帮助! 谢谢!

为了屏蔽图像我也做了:

-(void)clipView :(MyUIBezierPath*)path drawingView:(DrawingView*)myView
{
    MyUIBezierPath *myClippingPath =path;
    CAShapeLayer *mask = [CAShapeLayer layer];
    mask.path = myClippingPath.CGPath;
    myView.layer.mask = mask;
}

但是 colorWithPatternImage 和这个掩码有同样的技巧,即让我只在路径内部绘制,我现在面临的问题是:它对在路径边界周围的触摸点上绘制产生不良影响!

最佳答案

它通过 colorWithPatternImage 使用我自己的 mask 方法,虽然通过裁剪 mask 它是一回事。绘图问题是因为在方法“calculateMinImageArea:CGPoint1:CGPoint2:CGPoint3”中在触摸点绘制图像。更改其尺寸(根据线宽的高度宽度)对其进行排序。

关于ios - 在 UIView 中绘制触摸点会在边界上产生模糊的绘制效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30709045/

相关文章:

ios - dequeueReusableCellWithIdentifier 中的副标题

iOS - 尝试实现动画时钟 : Unable to simultaneously satisfy constraints runtime error -noob level 99

ios - 如何在 NSDate 中添加毫秒?

更新 `isHidden`后iOS设置 `alpha`

ios - cellForRowAtIndexPath 中的 Segue 不发送数据

ios - 为以编程方式生成的 View 实现自动布局

iOS UIView 在整个代码中添加和删除 subview

ios - NSURLSession 生命周期和基本授权

ios - 从 nib 自定义 UiTableViewCell 而不重用?

iPhone 应用程序因 admob 而崩溃?