You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
STBI not loading image despite giving the right directory for absolutely no reason #1833
@MyoskSoftwareCompany Could you upload the PNG image you are using here and I'll verify whether the image format is supported by stb_image. It would be nice if you could create a short C++ project that reproduces the problem.
@MyoskSoftwareCompany I downloaded the image you uploaded. After testing, the image is fine and it can be read correctly by stb_image.
If it is not readable in your project, please change the path to an absolute path instead of a relative path and retest again. Because the current directory may not be what you expected.
This PNG image is stored in RGB24 format, which means that one pixel takes up 3 bytes. Because you passed 0 to the desired_channels parameter of the stbi_load() function, you get a pixel buffer where a pixel is also stored 3 bytes next to each other. If a pixel takes up 4 bytes in your frame buffer, then you need to copy it pixel by pixel.
If you want each pixel of the loaded image data to take up 4 bytes instead of 3, pass STBI_rgb_alpha in the desired_channels parameter of the stbi_load() function, which means that each pixel of the load is stored in the RGBA32 format, taking up 4 bytes per pixel, which makes it easier to reading.
STBIDEF stbi_uc *stbi_load(charconst *filename, int *x, int *y, int *comp, int req_comp)
{
FILE *f = stbi__fopen(filename, "rb");
unsignedchar *result;
if (!f) returnstbi__errpuc("can't fopen", "Unable to open file");
result = stbi_load_from_file(f,x,y,comp,req_comp);
fclose(f);
return result;
}
As you can see from the output message and the source code, the reason is that it is not possible to open this file, which may not be able to find the file based on the path. Please check the file path and test using the full path (absolute path) of the file.
You run the program at C:\Users\Admin\Documents\dm. in fact, the current path is at C:\Users\Admin\Documents\dm. If you use relative paths, are you sure the path of the picture is C:\Users\Admin\Documents\dm\assets\title.png?
Repository owner locked and limited conversation to collaborators on Sep 1, 2025
Activity
yixy-only commentedon Sep 1, 2025
@MyoskSoftwareCompany Could you upload the PNG image you are using here and I'll verify whether the image format is supported by stb_image. It would be nice if you could create a short C++ project that reproduces the problem.
MyoskSoftwareCompany commentedon Sep 1, 2025
nothings commentedon Sep 1, 2025
What does the
stbi_failure_reason()printf show?yixy-only commentedon Sep 1, 2025
@MyoskSoftwareCompany I downloaded the image you uploaded. After testing, the image is fine and it can be read correctly by stb_image.
STBI_rgb_alphain thedesired_channelsparameter of thestbi_load()function, which means that each pixel of the load is stored in the RGBA32 format, taking up 4 bytes per pixel, which makes it easier to reading.MyoskSoftwareCompany commentedon Sep 1, 2025
the issue still persists
yixy-only commentedon Sep 1, 2025
@MyoskSoftwareCompany Yes!
As you can see from the output message and the source code, the reason is that it is not possible to open this file, which may not be able to find the file based on the path. Please check the file path and test using the full path (absolute path) of the file.
You run the program at
C:\Users\Admin\Documents\dm. in fact, the current path is atC:\Users\Admin\Documents\dm. If you use relative paths, are you sure the path of the picture isC:\Users\Admin\Documents\dm\assets\title.png?