使用SDL读取16x16图像的像素值

时间:2014-07-01 21:41:35

标签: c++ sdl-image

我使用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

0 个答案:

没有答案
相关问题