DevIL/OpenIL 未加载 Alpha 通道

DevIL/OpenIL isn't loading alpha channel

我遇到一个问题,我想使用 DevIL 作为字节数组加载的 .png 图像没有 alpha 通道。

全黑图像也显示为 alpha 通道值为 0。

这是我的图片加载函数:

DevILCall(ilGenImages(1, &m_ImageID));
DevILCall(ilBindImage(m_ImageID));

ASSERT("Loading image: " + path);

DevILCall(ilLoadImage(path.c_str()));

GraphicComponents::Image image(
    ilGetData(),
    ilGetInteger(IL_IMAGE_HEIGHT),
    ilGetInteger(IL_IMAGE_WIDTH),
    ilGetInteger(IL_IMAGE_BITS_PER_PIXEL)
);

return image;

我使用的Image对象如下:

struct Image
{
    ILubyte * m_Image;
    const unsigned int m_Height;
    const unsigned int m_Width;
    const unsigned int m_BPP;

    Image(ILubyte imageData[ ], unsigned int height, unsigned int width, unsigned int bpp);
    ~Image();
};

这就是我现在打印图像数据的方式:

for(unsigned int i = 0; i < image->m_Height*image->m_Width*4; i+=4)
{
    LOG("Red:");
    LOG((int) image->m_Image[i]);
    LOG("Green:");
    LOG((int) image->m_Image[i+1]);
    LOG("Blue:");
    LOG((int) image->m_Image[i+2]);
    LOG("Alpha:");
    LOG((int) image->m_Image[i+3]);
}

我也尝试过使用 ilTexImage() 将加载的图像格式化为 RGBA 格式,但这似乎也不起作用。当我将循环变量的最大值更改为图像中像素数的 4 倍时,打印循环开始读取垃圾值。

该图像也被确认具有 alpha 通道。 这里可能出了什么问题?

编辑:ilGetInteger(IL_IMAGE_BPP) 返回 3,目前应该表示 RGB。当我使用 ilTexImage() 强制 4 个通道时,然后 ilGetInteger(IL_IMAGE_BPP) returns 4 但我仍然看到垃圾值在标准输出

中弹出

加载图像后通过简单的 ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE) 调用解决了该问题。

我想 DevIL 默认以 RGB 模式使用无符号字节值加载图像,否则,您需要使用 ilConvertImage().

转换加载的图像