存儲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