2

私は基本的に、別の目的で iSteam/iFog alebit の非常に単純なバージョンに似たものを作成しようとしています。実際には、2 つのイメージがあり、1 つは主題のイメージで、もう 1 つは凝縮などのイメージです。次に、ユーザーが画面上で指を拭くと、一番上のレイヤーからそれが「切り取られ」、下のレイヤーが表示されます。これまでのところ、CoreGraphics とストロークを使用して画面に基本的な線を描くことができましたが、これを蒸気レイヤーのアルファ マスクとして使用する方法が見つかりません。

誰かが私に何を使うべきか、またはさらに良いサンプルコードについてアドバイスをくれたら、私は非常に感謝しています。これが私がこれまでに持っているものです:


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

mouseSwiped = YES;
UITouch *touch = [touches anyObject];   
CGPoint currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[drawImage.image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 36.0);
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextBeginPath(context);

CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();

}

4

1 に答える 1

3

呼び出したいメソッドはCGContextClipToMask. 「スチーム」イメージを描画してから、別の CGImage にストロークを描画するだけです。次に、蒸気をストロークにクリップします。このようなもの:

- (void)somewhereElse{
    UIImage *steam = [[UIImage imageNamed:@"steamImage.png"] retain];
    steamRef = steam.CGImage;
    //...
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, self.bounds, steamRef);         //draw the main image
    CGContextClipToMask(context, self.bounds, maskRef);         //respect alpha mask
    //where maskRef is a GCImage of your stroked path
}
于 2010-02-06T00:22:49.973 に答える