現在タッチされているポイントの色を取得しようとしているアプリケーションを作成しています。このポイントが黒でない場合、反復/再帰が実行され、黒以外のすべてのポイントが配列に格納されます。私は反復のためにこの関数を使用しています:
-(void)function:(CGFloat)positiveX:(CGFloat)positiveY:(CGFloat)negativeX:(CGFloat)negativeY
{
if (canDoPositiveX == YES)
{
//Checking in positive
if (![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX, positiveY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"])
{
CGPoint point = CGPointMake(positiveX, positiveY);
[array addObject:[NSValue valueWithCGPoint:point]];
[self function:positiveX+1 :positiveY :negativeX :negativeY];
}
else
{
canDoPositiveX = NO;
}
}
if (canDoPositiveY == YES)
{
//Checking in positive
if (![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX, positiveY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 0"])
{
CGPoint point = CGPointMake(positiveX, positiveY);
[array addObject:[NSValue valueWithCGPoint:point]];
[self function:positiveX :positiveY+1 :negativeX :negativeY];
}
else
{
canDoPositiveY = NO;
}
}
if (canDoNegativeX == YES)
{
//Checking in negative
if (![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(negativeX, negativeY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"])
{
CGPoint point = CGPointMake(negativeX, negativeY);
[array addObject:[NSValue valueWithCGPoint:point]];
[self function:positiveX :positiveY :negativeX-1 :negativeY];
}
else
{
canDoNegativeX = NO;
}
}
if (canDoNegativeY == YES)
{
//Checking in negative
if (![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(negativeX, negativeY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"])
{
negativeY -= 1;
CGPoint point = CGPointMake(negativeX, negativeY);
[array addObject:[NSValue valueWithCGPoint:point]];
[self function:positiveX :positiveY :negativeX :negativeY-1];
}
else
{
canDoNegativeY = NO;
}
}
NSLog(@"%u",[array count]);
}
今、私は配列にあるそれらのポイントの色を変更していますが、すべてのピクセルではなく、ポイントの直線のみに色を付けています。どんな助けでも本当に感謝します。ありがとう!