gpt4 book ai didi

objective-c - Objective-C : Check if UIImage is filled with a single color

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:41 24 4
gpt4 key购买 nike

有没有一种方法可以检查 UIImage 是否包含单一颜色?我有一个将文本呈现为图像的应用程序,如果返回的图像是全白的,我不想重绘屏幕。

有什么办法可以实现吗?

问候,EZ碎片

最佳答案

像这样的事情可能会成功

- (BOOL)imageIsWhite:(UIImage *)img {
CGImageRef imageRef = img.CGImage;
NSData *data = (NSData *) CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
unsigned char *pixels = (unsigned char *)[data bytes];
BOOL isWhite = YES;

for(int i = 0; i < [data length]; i += 4) {
if (!(pixels[i] == pixels[i+1] == pixels[i+2] == 255)) {
isWhite = NO;
break;
}
}
return isWhite;
}

关于objective-c - Objective-C : Check if UIImage is filled with a single color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8486330/

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