How to check pixel color of a UIView or a UIImage?

只谈情不闲聊 提交于 2019-12-04 15:32:54
verec

If you go back to that answer, the following (untested) snippet should get you started:

- (BOOL) checkForUniqueColor: (UIImage *) image {
    CGImageInspection * inspector = 
        [CGImageInspection imageInspectionWithCGImage: [image CGImage]] ;

    for (CGFloat x = 0 ; x < image.size.width ; x += 1.0f) {
        for (CGFloat y = 0 ; y < image.size.height ; y += 1.0f) {
            CGFloat red ;
            CGFloat green ;
            CGFloat blue ;
            CGFloat alpha ;

            [inspector colorAt: (CGPoint) {x, y}
                           red: &red
                         green: &green
                          blue: &blue
                         alpha: &alpha
            ] ;

            if (red == ... && green == ... && blue == ... && alpha == ...) {

            }
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!