I use SDL_image to load an image to a SDL_Surface
. How can I get all this data into a vector <int> pixels
?
I have tried:
Uint32 GetPixel(SDL_Surface *img, int x, int y) {
SDL_LockSurface(img);
//Convert the pixels to 32 bit
Uint32 *pixels = (Uint32 *)img->pixels;
//Get the requested pixel
return pixels[(y * img->w) + x];
SDL_LockSurface(img);
}
And I wonder why I get strange results... with a 3x3 Image with a black pixel in the center i get:
[0] (0, 0): 255, 255, 255
[1] (0, 1): 255, 255, 255
[2] (0, 2): 255, 255, 255
[3] (1, 0): 255, 255, 255
[4] (1, 1): 255, 0, 0 //WHY IS THIS NOT 0,0,0?
[5] (1, 2): 255, 255, 255
[6] (2, 0): 255, 255, 255
[7] (2, 1): 255, 255, 255
[8] (2, 2): 255, 255, 255