newbie colour-detect question

Started by
0 comments, last by Mole 24 years, 3 months ago
I want to read the colour of a pixel at a certain co-ordinate of a bitmap, and if it''s green, say, I want to do something, but if it''s magenta, don''t do it. Can someone write me a bit of code for it? I''m using DJGPP and Allegro, ATM
Advertisement
That depends on the color depth you are using partially. If you are using 8 bit color, then a pixel is gonna be 1 byte, and you are going to have a color palette. If you are using 16 bit color, then you''re gonna have an unsigned short, and if it''s 32 bit, you have an unsigned long. I assume you already know how to build color values. All you have to do is something like this:
if(bitmap.buffer[x + (y * bitmap.width)] == color){  // do stuff here} 

I hope that was understandable...

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge

This topic is closed to new replies.

Advertisement