I am making a Program that copies each individual pixel of a .bmp file onto another, I believe that my if statement tries is trying to keep the image being copied from going out of bounds but isn’t working. im fairly new to c++ and this is really confusing me.
[edit: spelling]
//note that this is the button.cc file, not the main im 90% certain the problem lies here
#include "robot.h"
#include <iostream>
#include "cpputils/graphics/image.h"
#include <string>
using std::string;;
using std::endl;
void Robot::Draw(graphics::Image &my_image) {
if ((integer % 2) == 0) {
graphics::Image robot1;
robot1.Load(fileName1_);
int width = robot1.GetWidth();
int height = robot1.GetHeight();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
graphics::Color color = robot1.GetColor(i, j);
//CHECKS IF ITS OUT OF BOUNDS
if (i <= my_image.GetWidth() && j <= my_image.GetHeight()) {
my_image.SetColor(i - x_ + (width / 2), j - y_ + (height / 2),
color);
}
}
}
integer++;
}
else {
graphics::Image robot2;
robot2.Load(fileName2_);
int width = robot2.GetWidth();
int height = robot2.GetHeight();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
graphics::Color color = robot2.GetColor(i, j);
//CHECKS IF ITS OUT OF BOUNDS
if (i <= my_image.GetWidth() && j <= my_image.GetHeight()) {
my_image.SetColor(i - x_ + (width / 2), j - y_ + (height / 2), color);
}
}
}
integer++;
}
}
Source: Windows Questions C++