0

2 つの画像を使用して Blender アプリで提供されているものと同様に、iOS で画像マスクのような機能を実装しています。これが私のタッチムーブコードです:-

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:staticBG1];

    UIGraphicsBeginImageContext(view.frame.size);
    [image_1 drawInRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 20.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());

    image_1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;
    mouseMoved++;
    if (mouseMoved == 10)
        mouseMoved = 0;
}

上記のコードは、次のような効果を生成しています。

今私が本当に欲しいのは真っ赤な線ではなく、それらの場所の別の画像からのピクセルです。両方の画像は同じ寸法です。どうすればいいのですか??手動の画像処理方法をピクセル アクセスに実装しようとしましたが、遅すぎたため、これはリアルタイムで行われます。

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); に代わるものはありますか? ?

4

1 に答える 1

2

パスに色やパターンを描画しないでください。透明度を描画します。消去される画像の背後にある独自のレイヤーに 1 つの画像が必要です。そのままパスを作成しますが、色を設定する代わりに、ブレンド モードをクリア ( kCGBlendModeClear) に設定します。

これにより、画像の一部が削除され、下の画像が透けて見えるようになります。


交換:

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);

と:

CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); 
于 2013-10-07T07:11:08.047 に答える