1

我正在使用 lwjgl 的端口stb_image来加载jpg图像。问题是,我总是得到一个nullByteBuffer因为什么都没有加载。这是代码:

int[] width = new int[1], height = new int[1], nrChannels = new int[1];

ByteBuffer data = stbi_load("/textures/container.jpg",width, height,nrChannels,0);

if(data == null)
    throw new RuntimeException("Failed to load texture."); //I get this exception.

我的纹理的位置:

在此处输入图像描述

我当然是这样尝试的:

ByteBuffer data = stbi_load("container.jpg",width, height,nrChannels,0);

同样的结果,没有加载。我究竟做错了什么?

4

1 回答 1

1

您提供给 stbi_load() 的路径并不是一个类路径资源,而是一个文件系统路径。

于 2018-03-24T14:55:29.627 回答