我使用 SDL_image 将图像加载到SDL_Surface
. 我怎样才能将所有这些数据放入一个vector <int> pixels
?
我努力了:
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);
}
我想知道为什么我会得到奇怪的结果......我得到一个 3x3 图像,中间有一个黑色像素:
[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