'Initialising stbi_uc without loading an image
I have what seems like an elementary question, but I can't find an answer.
I want to initialise a new stbi_uc object, setting its dimensions and so on, without loading an image into it. (This is because the program itself will be creating an image using this object, so there's no need to load anything.) I can't find a way to do this. I'm using a clumsy workaround at the moment where I create a blank SFML image of the desired dimensions, save it to disk, and then load that back into the stbi_uc object:
int width=500;
int height=500;
sf::Image *templateimage=new sf::Image;
templateimage->create(width,height,sf::Color(0,0,0));
bool const ret1(templateimage->saveToFile("Templateimage.tga"));
if (!ret1) {cerr << "Error writing Templateimage.tga" << endl;}
delete templateimage;
int imagewidth, imageheight, imagechannels;
stbi_uc *myimage=new stbi_uc;
myimage=stbi_load("Templateimage.tga",&imagewidth,&imageheight,&imagechannels,STBI_rgb_alpha);
This works, but it is surely ridiculous. What I really want to do is something like this:
stbi_uc *myimage=new stbi_uc(width,height,channels);
But that's not possible. I've tried this, but it doesn't generate the correct size:
stbi_uc *myimage=new stbi_uc(width*height*channels);
Is there a better way to do this than what I've got now? Even converting the sf::Image directly into the stbi_uc without having to save/load it would be an improvement.
Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
