检查像素颜色Allegro 5 C ++ [英] Checking pixel color Allegro 5 C++

查看:97
本文介绍了检查像素颜色Allegro 5 C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查屏幕上的像素是否为红色。我正在使用快板5。这是我的代码

I want to check if a pixel on the screen is red or not . I am using allegro 5 . Here is my code

ALLEGRO_BITMAP *bitmap ;
int x , y;

x=*xIter-20;
y=*yIter;

ALLEGRO_COLOR red_color = al_map_rgb (255,0,0);
ALLEGRO_COLOR new_color = al_get_pixel (bitmap , x , y);

if(new_color==red_color)
    return 1;

但是它报告一个sytnax错误

But it reports a sytnax error


错误C2678:二进制'==':未找到采用左手
操作数为'ALLEGRO_COLOR'类型的操作符(或没有可接受的
转换)

error C2678: binary '==' : no operator found which takes a left-hand operand of type 'ALLEGRO_COLOR' (or there is no acceptable conversion)


推荐答案

unsigned char r,g,b;
al_unmap_rgb(new_color, &r, &g, &b);

bool isColorRed = (r == 255 && g == 0 && b == 0);

这篇关于检查像素颜色Allegro 5 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆