ios - 如何在 iOS 中检测颜色并打印其名称?
<p><p>如何检测图像/摄像头上的主色并打印其名称?</p>
<p>例如:在图像中可能有非常浅的蓝色、浅蓝色、蓝色、深蓝色,只是因为该物体或图像上的闪电,当我分析我想要制作的图像时,我知道主色是蓝色,然后打印屏幕上的“蓝色”。如果我需要使用 RGB,我想我需要颜色范围,对吗? </p>
<p>ps:图像上也可以有红色、黄色等,但我想检测主色。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>- (UIColor *)averageColor {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char rgba;
CGContextRef context = CGBitmapContextCreate(rgba, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), self.CGImage);
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
if(rgba > 0) {
CGFloat alpha = ((CGFloat)rgba)/255.0;
CGFloat multiplier = alpha/255.0;
return )*multiplier
green:((CGFloat)rgba)*multiplier
blue:((CGFloat)rgba)*multiplier
alpha:alpha];
}
else {
return )/255.0
green:((CGFloat)rgba)/255.0
blue:((CGFloat)rgba)/255.0
alpha:((CGFloat)rgba)/255.0];
}
}
</code></pre>
<p>来自 <a href="https://stackoverflow.com/questions/13694618/objective-c-getting-least-used-and-most-used-color-in-a-image" rel="noreferrer noopener nofollow">Objective-c - Getting least used and most used color in a image</a> </p>
<p>来自 <a href="http://www.bobbygeorgescu.com/2011/08/finding-average-color-of-uiimage/" rel="noreferrer noopener nofollow">http://www.bobbygeorgescu.com/2011/08/finding-average-color-of-uiimage/</a> </p></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中检测颜色并打印其名称?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22838315/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22838315/
</a>
</p>
页:
[1]