gpt4 book ai didi

iphone - Objective-C : How do I draw lines with alpha in quad curve

转载 作者:行者123 更新时间:2023-11-29 13:32:35 25 4
gpt4 key购买 nike

当我使用四边形曲线点时,我在点方面遇到了麻烦。我想为我的线设置不透明度,但我在这里也看到了点。这是我的代码..

CGPoint midPoint(CGPoint p1,CGPoint p2)
{
return CGPointMake ((p1.x + p2.x) * 0.5,(p1.y + p2.y) * 0.5);
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event//upon touches
{
UITouch *touch = [touches anyObject];

previousPoint1 = [touch locationInView:self.view];
previousPoint2 = [touch locationInView:self.view];
currentTouch = [touch locationInView:self.view];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event//upon moving
{
UITouch *touch = [touches anyObject];

previousPoint2 = previousPoint1;
previousPoint1 = currentTouch;
currentTouch = [touch locationInView:self.view];

CGPoint mid1 = midPoint(previousPoint2, previousPoint1);
CGPoint mid2 = midPoint(currentTouch, previousPoint1);

UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
[imgDraw.image drawInRect:CGRectMake(0, 0, 1024, 768)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context,kCGLineCapRound);
CGContextSetLineWidth(context, slider.value);
CGContextSetBlendMode(context, blendMode);
CGContextSetRGBStrokeColor(context,red, green, blue, 0.5);
CGContextBeginPath(context);
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGContextStrokePath(context);

imgDraw.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();
endingPoint=currentTouch;
}

任何答案将不胜感激。

最佳答案

您需要做的是保留用户到目前为止输入的所有点的列表,并始终将所有这些点重新绘制为同一路径的一部分。

你需要一个数组来存储点。类似

CGPoint points[kMaxNumPoints];

而不是 previousPoint1/2 等。然后在 touchesMoved: 中,您将循环访问这些点。像这样:

CGContextBeginPath (context);
CGContextMoveToPoint (context, points [ 0 ].x, point [ 0 ].y);
for (int i = 1; i < currNumPoints; i++)
{
// I wasn't sure from your example if you wanted the mid point here instead of the
// previous point. But you get the idea.
CGContextAddQuadCurveToPoint (context, points [ i - 1 ].x, points [ i - 1 ].y, point [ i ].x, point [ i ].y);
}
CGContextStrokePath (context);

关于iphone - Objective-C : How do I draw lines with alpha in quad curve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11497069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com