The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
How do I find the color of a surface's pixel in RGBA , inclu
Parikshit Singh
Guest

I have a surface with me in SDL which has some alpha in it. I want to
find the alpha value of a specific pixel. I also wanted to know if I can
fill a pixel with alpha (erasing the pixel).
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
mr_tawan


Joined: 13 Jan 2014
Posts: 161
Here's the basic idea.

1. Lock the surface using SDL_LockSurface().
2. Get the pixel value from the buffer at `surface->pixels`. Use the pitch and row to calculate the exact location of the pixel.
3. After get the pixel value, use `SDL_GetRGBA` to get the r,g,b,a value of that pixel. The pixel format is available at `surface->format`.
4. Unlock the surface