我有一个 .PNG 文件。该图像有白色背景,只有黑色线条。
我想在用户触摸图像时检测到黑线。在此图像中,我如何通过触摸检测花朵的线条
例如
这怎么可能?
请帮帮我...
最佳答案
创建UIView
类的类别。添加以下功能。
@implementation UIView (ColorOfPoint)
- (UIColor *) colorOfPoint:(CGPoint)point
{
unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapFloatComponents);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.layer renderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIColor *color = [UIColor colorWithRed:pixel[0]/255.0 green:pixel[1]/255.0 blue:pixel[2]/255.0 alpha:pixel[3]/255.0];
return color;
}
@end
通过以下调用使用它:
UIColor *col = [YOUR_IMAGE_VIEW colorOfPoint:CGPOINT_WHERE_USER_TOUCHED];
关于ios - 检测图像 ios 上的黑线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19519116/