从 allegro5 中的显示器获取像素颜色

Getting pixel color from display in allegro5

我一直在尝试检查像素颜色是否为绿色,我看到了这个:

Checking pixel color Allegro 5 C++,

但我的代码中没有位图。

我在 allegro5 文档中搜索,似乎没有什么可以帮助我的。

有什么方法可以将显示转换为位图吗?或者从显示器中获取像素颜色?任何人都知道该怎么做?我有像素的位置,仅此而已。

使用 al_get_backbuffer to get the display as a bitmap, then use al_get_pixel 检索像素。

我尝试了以下方法并得到了一些结果

    ALLEGRO_BITMAP *bitmap;
    bitmap = al_get_backbuffer(display);
    ALLEGRO_COLOR color = al_get_pixel(bitmap,x,y);

    bool isBlack = (color.r ==0 && color.g == 0 && color.b ==0);
    if(!isBlack){
        alive=0;
        explode() or something
    }