0

まず第一に、私はobjective-cの初心者だと言いたいです。

1つの画像(赤、緑、青の3色の.png画像)を単純に描画するアプリを作成したことを知るまで。アプリケーションは、画像全体に線を描画します。

私が欲しいのは、タッチ(マウス)が他の色を上げても、1色(例:赤)だけで線を描くことです。(...インターネットで読んだように、フラッドフィルアルゴリズムを使用して行う必要があります)

これを行う方法についていくつかのアイデアを教えてください。

私が今使っているコード:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;

UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];

UIGraphicsBeginImageContext(CGSizeMake(320, 568));
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 2, 0, 2);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());


[drawImage setFrame:CGRectMake(0, 0, 320, 568)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;

[self.view addSubview:drawImage];
}

事前にt​​hnx。

4

1 に答える 1

0

messageから派生したカスタム クラスを作成しUIView、メッセージをオーバーライドできますdrawRect:。次に、描画コードを に配置しますdrawRect:。上のサブビューとしてこのカスタム クラスを追加しますUIImageView

#import <QuartzCore/QuartzCore.h>
@interface YourView : UIView {
    ...
}


in .m file
- (void)drawRect:(CGRect)rect{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //your drawings
}
于 2012-11-08T04:37:18.597 に答える