gpt4 book ai didi

iphone - 逐像素检查 UIImage

转载 作者:可可西里 更新时间:2023-11-01 03:11:39 25 4
gpt4 key购买 nike

我正在创建一个应用程序,我试图在其中获取当前触摸点的颜色,如果该点不是黑色,那么它将运行迭代/递归并将所有非黑色点存储在数组中。我正在使用此函数进行迭代:

-(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]);

}

现在,我正在改变数组中那些点的颜色,但它只为点的直线着色,而不是每个像素。任何帮助将不胜感激。谢谢!

最佳答案

试试这个。我无法实际测试它,但它应该可以工作。

-(void)function:(CGFloat)positiveX:(CGFloat)positiveY:(CGFloat)negativeX:(CGFloat)negativeY
{
// Check your current point
if ([[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX, positiveY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"])
{
// reached the dead end (break recursion)
return;
}

CGPoint point = CGPointMake(positiveX, positiveY);
[array addObject:[NSValue valueWithCGPoint:point]];

BOOL canDoPositiveX = ![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX+1, positiveY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"];
BOOL canDoPositiveY = ![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX, positiveY+1)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"];
BOOL canDoNegativeX = ![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX-1, positiveY)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"];
BOOL canDoNegativeY = ![[NSString stringWithFormat:@"%@",[self colorOfPoint:CGPointMake(positiveX, positiveY-1)]] isEqualToString:@"UIDeviceRGBColorSpace 0 0 0 1"];

if (canDoPositiveX == YES)
{
[self function:positiveX+1 :positiveY :negativeX :negativeY];
}

if (canDoPositiveY == YES)
{
[self function:positiveX :positiveY+1 :negativeX :negativeY];
}

if (canDoNegativeX == YES)
{
[self function:positiveX :positiveY :negativeX-1 :negativeY];
}

if (canDoNegativeY == YES)
{
[self function:positiveX :positiveY :negativeX :negativeY-1];
}

NSLog(@"%u",[array count]);
}

同时从您的类 canDoPositiveX、canDoPositiveY、canDoNegativeX、canDoNegativeY 中删除这些变量

关于iphone - 逐像素检查 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15633335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com