我正在尝试制作一个可以控制画笔不透明度的绘图应用程序,但是当我尝试降低不透明度时,结果是这样的。我使用了核心图形。 (检查图像)。

我将如何解决此问题?

这是我的一些代码。

 -(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;
}

最佳答案

不要用-touchesMoved:withEvent:绘制图形。在任何事件方法中,您都应该更新需要绘制的内容,然后发送-setNeedsDisplay.
在上面编写代码时,您正在从事件消息获得的每对位置之间创建一条路径。

您应该在-touchesBegan:withEvent:中创建路径,并在-touchesMoved:withEvent:中添加路径。

关于objective-c - Objective-C:触摸绘图不透明度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11499652/

10-13 05:06