Checking pixel color Allegro 5 C++

被刻印的时光 ゝ 提交于 2019-12-11 20:38:01

问题


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;

But it reports a sytnax error

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


回答1:


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

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



回答2:


There isn't operator == for ALLEGRO_COLOR type, you need to it yourself.



来源:https://stackoverflow.com/questions/16958922/checking-pixel-color-allegro-5-c

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