-1

このコードを使用して、quartz2dで線を描画します

CGPoint currentPoint = CGPointMake(rascalImage.center.x, rascalImage.center.y);
        currentPoint.y += 10;


        UIGraphicsBeginImageContext(self.view.frame.size);
        [drawingView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
        CGContextBeginPath(UIGraphicsGetCurrentContext());
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        lastPoint = currentPoint;

では、消しゴムが交差する場所だけに消しゴム関数を作成するにはどうすればよいでしょうか。線(消しゴムが接触している部分)から特定のポイントを消去する必要があることはわかっていますが、これを行う方法がわからないので、助けてください!!

4

2 に答える 2

1
        UIGraphicsBeginImageContext(imgBlankView.frame.size);
        [imgBlankView.image drawInRect:CGRectMake(0, 0, imgBlankView.frame.size.width, imgBlankView.frame.size.height)];

        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(),lineWidth);
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);

        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
        CGContextBeginPath(UIGraphicsGetCurrentContext());  
        CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);

        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint1.x, lastPoint1.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        imgBlankView.image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();
于 2011-12-08T09:43:41.230 に答える
0

あなたは無地の背景に描いていないと思いますか?その場合は、同じ関数を使用して、対照的な線の上に背景色の線を描画します。

ただし、背景が複雑である可能性が高いため、グラフィックコンテキストを終了し、描画した線からUIImageを取得すると、線だけを消去する方法はありません。ある種の複雑な描画アプリを作成している場合は、レイヤーを使用し、レイヤーを積み重ねて描画環境を作成することをお勧めします。

この投稿もチェックしてください: iOSでUIImageViewの画像の一部を消去する方法は?

于 2011-08-26T23:41:09.143 に答える