在UIView上得到某一点的颜色值

发布时间:2020-07-30 23:28:07 作者:guoleiappleapp
来源:网络 阅读:763

- (UIColor *) colorOfPoint:(CGPoint)point

{

    unsigned char pixel[4] = {0};

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast);

    

    CGContextTranslateCTM(context, -point.x, -point.y);

    

    [self.layer renderInContext:context];

    

    CGContextRelease(context);

    CGColorSpaceRelease(colorSpace);

    

    NSLog(@"pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]);

    

    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;

}


推荐阅读:
  1. IOS UIView的跳转
  2. UIView视图

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

颜色 uiview 某一

上一篇:递归的小栗子

下一篇:Win10 下 Nodejs+Angular2+bootstrap4 开发环境搭建

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》