UIView 内で独自の「フラッド フィル」実装を構築しようとしています。すべてが順調に進んでいますが、UIImageView または UIView で特定のポイント/ピクセルの色を変更する方法がわかりません。
UIView 内のポイントまたはピクセルの色を変更するにはどうすればよいですか?
編集:
ここで私のシナリオ:
1- オンタッチ イベント:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint loc = [touch locationInView:_image];
UIColor *mycol=[self getPixelColorAtLocation:loc];
if (mycondition) {
_mylayer->point_=loc;
_mylayer->color_=mycol;
[_mylayer setNeedsDisplay];
}
}
私のカスタムに四角形を描くUIView
- (void)drawRect:(CGRect)rect {
if (point_.x>0) {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, color_.CGColor);
CGContextFillRect(context, CGRectMake(point_.x,point_.y, 1.0, 1.0));
}
}
私のポイントは、「[_mylayer setNeedsDisplay];
配置されたポイント(新しい色)を呼び出すたびに削除され、新しいポイント(1つのポイントのみ)が表示される.
何か案が