ios - 检测图像 ios 上的黑线

标签 ios ipad cocoa-touch core-graphics

我有一个 .PNG 文件。该图像有白色背景,只有黑色线条。

我想在用户触摸图像时检测到黑线。在此图像中,我如何通过触摸检测花朵的线条

例如

enter image description here

这怎么可能?

请帮帮我...

最佳答案

创建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/

相关文章:

ios - 更改 UIViewController 后 NSNotificationCenter 崩溃

iphone - 向网站发送数据并获取搜索结果 iOS

ios - NSTask 不适用于具有特殊字符的文件路径

cocoa-touch - 如何在我的 iPhone 应用程序中创建自定义广告?

ios - 无法在 iOS 的某些设备中获取 FCM 通知

ios - 使用弹出库时的不同 View 层次结构

ios - 单元格的详细 TextView 未显示?

javascript - IOS 上的 HTML5 音频 : how can currentTime be less than initial value?

iphone - 如何将 NSObject 从 NSDictionary 转换为 NSString?

ios - 共享扩展仅显示在 UIActivityViewController 的更多部分下?