如何使用cpp中的SOIL访问各个像素的颜色

时间:2014-07-28 13:02:54

标签: c++ soil

我想从各个像素访问RGB值。我知道我可以通过调用

获得一个unsigned char数组
unsigned char* pixels = SOIL_load_image(picturename.c_str(), &_w, &_h, 0, SOIL_LOAD_RGB);

但是我不明白这些字符是什么意思。文档说:

// The return value from an image loader is an 'unsigned char *' which points
// to the pixel data. The pixel data consists of *y scanlines of *x pixels,
// with each pixel consisting of N interleaved 8-bit components; the first
// pixel pointed to is top-left-most in the image. There is no padding between
// image scanlines or between pixels, regardless of format. The number of
// components N is 'req_comp' if req_comp is non-zero, or *comp otherwise.
// If req_comp is non-zero, *comp has the number of components that _would_
// have been output otherwise. E.g. if you set req_comp to 4, you will always
// get RGBA output, but you can check *comp to easily see if it's opaque.

然而,当我加载一个10 x 10像素的图像来测试它时,我在阵列中得到了一个巨大的字符(大约54000),这似乎太过分了。我如何获得单独的像素颜色,我可以做这样的事情:

int colourvalue = pixel[y*width+x];

我似乎无法找到这个

0 个答案:

没有答案