存储ilGetData()返回的正确方法是在IL无符号字节数组中。
例如
ILubyte * bytes = ilGetData();
遍历它在一个for循环使用
for(int i = 0; i < size; i++)
{
// Print out each ILubyte one at time
printf("%d\n", bytes[ i ]);
}
你可能想要的是一个for循环,打印或做别的事情与RGB值在给定的像素为图像中的所有像素。正如Bart指出的,下面的排序是针对IL_RGBA或RGBA格式的。如果使用IL_RGB,那么4将变成3,并且如果使用IL_BGR或IL_BGRA,则需要按预期切换红色和蓝色值。
ILuint width,height;
width = ilGetInteger(IL_IMAGE_WIDTH);
height = ilGetInteger(IL_IMAGE_HEIGHT);
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
printf("%s\n", "Red Value for Pixel");
printf("%d\n", bytes[(i*width + j)*4 + 0]);
printf("%s\n", "Green Value for Pixel");
printf("%d\n", bytes[(i*width + j)*4 + 1]);
printf("%s\n", "Blue Value for Pixel");
printf("%d\n", bytes[(i*width + j)*4 + 2]);
}
}
你的例子假定RGBA是一种格式,我认为? – Bart 2012-02-06 20:38:30
非常感谢您的支持。你已经解决了一个星期寻找我。代码示例非常感谢。再次感谢。 – Rohit 2012-02-07 13:49:27