I got this:
i'm working on borland C++ v3.1
i'm working with graphics.h
what i want is do capture the background into a matrix (dynamic memory) then draw some stuff over the captured area, and then i want to restore the backgound... but i get a strange result, maybe this code is wrong... i got ir from here in a question i made a couple of days ago...
Code:
class backgrnd{
protected:
int** matrix;
int x1, y1,
x2, y2;
public:
backgrnd(int, int, int, int);
~backgrnd();
};
backgrnd::backgrnd(int bx1, int by1, int bx2, int by2)
{
x1 = bx1; y1 = by1;
x2 = bx2; y2 = by2;
int i;
int* column;
matrix = new int*[y2-y1];
for (i = 0; i < y2-y1; i++)
matrix[i] = new int[x2-x1];
for (i = 0; i < (x2-x1); i++)
{
column = matrix[i];
for (int j = 0; j < (y2-y1); j++)
column[j] = getpixel(i+x1,j+y1);
}
}
backgrnd::~backgrnd(void)
{
int* column;
for (int i = 0; i < (x2-x1); i++)
{
column = matrix[i];
for (int j = 0; j < (y2-y1); j++)
putpixel(i+x1,j+y1,column[j]);
}
delete []matrix;
}
void main (void)
{
//here i open borland BGI with initgraph();
backgrnd *b = new backgrnd(270,100,400,400);
// here i draw a some stuff
delete b;
getch();
//here i close borland BGI with closegraph();
}