I searched and searched for an existing topic about this problem because I think I made a similar topic previously. I just couldn't find it.
I keep running into this problem every time I make a program that is manipulating images.
Eventually the image does not save as a file and no error report shows up. I just can't figure why it doesn't save. Previous attempts have shown extreme flippancy by influence of non related changes that only sometimes fix it every other time it runs. With this specific program I'm not experiencing any flippancies yet.
string sframe[100];
int numberOfFrames;
RectangleShape shape;
Crop::loadcrop(string filetype)
{
ifstream framelist("frames/frame list.txt");
for(int a=0;a<100;a++)
{
getline (framelist,sframe[a]);
if(sframe[a]=="")
{
numberOfFrames=a-1;
break;
}
sframe[a]+=filetype;
}
shape.setOutlineColor(Color::Red);
shape.setFillColor(Color::Transparent);
shape.setOutlineThickness(2.f);
shape.setSize(Vector2f(0,0));
}
int currentframe=0;
Texture texture;
Sprite sprite;
IntRect rect[100];
IntRect selectrect;
bool firstclick=false;
bool firsttap=false;
Crop::setcrop(RenderWindow &window)
{
if(currentframe<numberOfFrames)
{
texture.loadFromFile("frames/"+sframe[currentframe]);
sprite.setTexture(texture);
Vector2f MPosition=window.mapPixelToCoords(Mouse::getPosition(window));
if(Mouse::isButtonPressed(Mouse::Left))
{
shape.setPosition(MPosition.x,MPosition.y);
}
if(Keyboard::isKeyPressed(Keyboard::Space))
{
shape.setPosition(MPosition.x-shape.getSize().x,MPosition.y-shape.getSize().y);
}
shape.setSize(Vector2f(MPosition.x-shape.getPosition().x,MPosition.y-shape.getPosition().y));
selectrect=IntRect(shape.getPosition().x,shape.getPosition().y,shape.getSize().x,shape.getSize().y);
if(Keyboard::isKeyPressed(Keyboard::Return))
{
if(firsttap==false)
{
currentframe++;
firsttap=true;
rect[currentframe]=selectrect;
}
}
else
{
firsttap=false;
}
window.draw(sprite);
window.draw(shape);
}
else
{
save();
window.close();
}
}
Crop::save()
{
Image image[numberOfFrames];
Vector2i totalsize;
for(int x=1;x<numberOfFrames+1;x++)
{
image[x].loadFromFile("frames/"+sframe[x]);
}
Image saveimage;
Vector2i currentsize;
bool row=true;
Vector2i sizecheck;
for(int x=0;x<numberOfFrames;x++)
{
if(totalsize.x<1000)
{
totalsize.x+=rect[x].width;
}
if(sizecheck.x<1000)
{
sizecheck.x+=rect[x].width;
}
else
{
totalsize.y+=rect[x].height;
sizecheck.x=0;
}
}
saveimage.create(totalsize.x,totalsize.y,Color::Transparent);
for(int x=0;x<numberOfFrames;x++)
{
currentsize.x+=rect[x].width;
if(currentsize.x<=totalsize.x)
{
//
for(int x1=currentsize.x-rect[x].width;x1<currentsize.x;x1++)
{
for(int y=currentsize.y-rect[x].height;y<currentsize.y;y++)
{
saveimage.setPixel(x1,y,image[x].getPixel(x1-currentsize.x,y-currentsize.y));
}
}
}
else
{
currentsize.y+=rect[x].height;
currentsize.x=0;
}
}
saveimage.saveToFile("test/sheet.png");
//WHY DO I KEEP RUNNING INTO THIS PROBLEM WHERE IMAGES DONT SAVE AND SHOW NO ERROR?!
}
Ok.So my code is extremely confusing to anyone not familiar with my terms but i'm absolutely certain that the save() function is where the problem is. And it is certain that the images are loaded into
Image image[numberOfFrames];
without any problems since these images have been saved as separate files before I tried combining them into one image.The important thing is getting the image called "saveimage" to save to file.
Any ideas what wrong here?