Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Draw rgb information from al_get_pixel with al_draw_text

This thread is locked; no one can reply to it. rss feed Print
Draw rgb information from al_get_pixel with al_draw_text
geograman
Member #16,048
August 2015

Heyho,

can someone show me the most effective way of how to use al_draw_text to draw the rgb information from al_get_pixel.

I tried to do this:

currentPixel = al_get_pixel(image, w, h);
al_unmap_rgb(currentPixel, &r, &g, &b);
al_draw_text(currentFont, al_map_rgb(255, 255, 255), 50, 50, ALLEGRO_ALIGN_LEFT, r);

but al_draw_text wants to have a const char.

Bruce Perry
Member #270
April 2000

//Extract the colour values
unsigned char r, g, b;
al_unmap_rgb(currentPixel, &r, &g, &b);

//Use the formatted text function
al_draw_textf(currentFont, al_map_rgb(255, 255, 255), 50, 50, ALLEGRO_ALIGN_LEFT, "(%d, %d, %d)", r, g, b);

...I didn't notice you'd already found al_unmap_rgb when I wrote that :)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

geograman
Member #16,048
August 2015

Wow, very straightforward, thanks a lot Bruce Perry! :)

Go to: