1

我正在尝试在我的应用程序中实现洪水填充算法。我从 GitHub 获得了一些代码。我需要以 int 的形式传递目标颜色和替换颜色。我尝试如下,

const CGFloat *components = CGColorGetComponents(color.CGColor);
NSString *colorAsString = [NSString stringWithFormat:@"%f,%f,%f,%f", components[0], components[1], components[2], components[3]];
 NSLog(@"colors original is %f %f %f %f",components[0],components[1], components[2], components[3]);
NSLog(@"original color is %d",[colorAsString intValue]);
UIColor *targetColor=[UIColor redColor];
const CGFloat *target = CGColorGetComponents(targetColor.CGColor);
NSString *colorAstarget = [NSString stringWithFormat:@"%f,%f,%f,%f", target[0], target[1], target[2], target[3]];
NSLog(@"colors target is %f %f %f %f",target[0], target[1], target[2], target[3]);

NSLog(@"target color is %d",[colorAstarget intValue]);

但是我在 NSLogs 中将两者都设为 1,以便洪水填充返回 0。请帮助我,谢谢

4

0 回答 0