c++ - DevIL/OpenIL 没有加载 alpha 通道
问题描述
我遇到了一个问题.png
,我想使用 DevIL 作为字节数组加载的图像没有 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)
返回 4 但我仍然看到在 std 输出中弹出垃圾值
解决方案
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)
加载图像后,通过一个简单的调用解决了该问题。
我想 DevILRGB
默认以无符号字节值的模式加载图像,否则,您需要使用ilConvertImage()
.
推荐阅读
- go - 如何通过reflect.TypeOf(interface {})从struct遍历* T funcs?
- reactjs - 如何将变量插入从其他文件导入的变量名中?
- excel - 在 MS Excel VBA 中静默填写 Web 表单
- javascript - PortalVue 可以跨多个 Vue.js 单文件组件使用吗?
- java - 从资源文件夹中读取文件,InputStream 为空
- android - Textview drawable 不在远程视图中显示可绘制图像
- zurb-foundation - 如何解决 Foundation Sites v6.5.3 中的 XY-Grid 响应行为挑战
- javascript - 循环事件监听函数
- reactjs - create-react-app 将所有请求转为 https
- go - 为什么在 Go 中调用嵌入字段的方法时,Type Alias 和 Type 的行为不同?