Sign in to follow this  
raptorstrike

getting individual pixle color from bitmap

Recommended Posts

my thread name pretty much says it all. how would you do that in SDL i know that there is a pixle data * and a mask[RBG] within that struct but i cant really see it as a statement or algorithm can some one help me out here can i do somthing like this SDK_Surface* X; X = SDL_LoadBMP("foo.bmp"); if(X->SDL_PixleFormat->Rmask == 0) that kinda thing? i cant help but think there has to be an array there some were

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Alright you have to do this, there is a function in the SDL documentation here it is. . .


Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

switch(bpp) {
case 1:
return *p;

case 2:
return *(Uint16 *)p;

case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0]

then do this


SDL_Surface* X;

X = SDL_LoadBMP("foo.bmp")
int xcoor, ycoor;
Uint8 R, G, B;
SDL_GetRGB(getpixel(X, xcoor, ycoor), X->format, &R, &G, &B);

Share this post


Link to post
Share on other sites
THANKS a ton i found that Get_RGB() but couldnt figure out what was wrong with the way i was calling and i never would have discovered that getpixel function had you not mentioned it. thanks!![grin][grin]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this