Help with TImage CopyArea

Hello
I am currently writing a data acquisition software for a camera in root.
The images acquired are stored in a framebuffer array using the TImage* class.
These can be saved and shown in a Canvas.

Now I want to copy the last acquired frame into a second TImage Object sum_image for integration. I am using the CopyArea Function for this:
framebuffer->GetLastImage()->CopyArea(sum_image,Xpx,Ypx,Xpx,Ypx,0,0,EGraphicsFunction::kGXand);

But somehow this does not work, when I plot the second image it is always empty. What do I miss in my code?

{	
int Xpx=1000;
int Ypx=1000;

double* data=new double[Xpx*Ypx];// frame data array
for (int i=0;i<Xpx*Ypx;i++)
{
	data[i]=0;
}
sum_image=new TASImage("Sum_Image",data,Xpx,Ypx); //create empty image for the integration
sum_image->Draw();

int N=10;
TImage** framebuffer=new TImage*[N];

for (int k=0;k<N;k++) // Acquire Framebuffer Memory
{
	framebuffer[k]=new TASImage(Xpx,Ypx);
}


//--- Acquire Frames --//
r=new TRandom();
for (int k=0;k<N;k++){
	
	for (int i=0;i<Xpx*Ypx;i++) // create Noise
	{
		data[i]=r->Rndm();
	}
	framebuffer[k]->SetImage(data,framebuffer[k]->GetWidth(),framebuffer[k]->GetHeight());
	framebuffer[k]->CopyArea(sum_image,Xpx,Ypx,Xpx,Ypx,0,0,EGraphicsFunction::kGXand);
}
gPad->Update();
/*
delete r;

for (int k=0;k<N;k++) // Delete Framebuffer Memory
{
	delete framebuffer[k];
}
delete[] framebuffer;

delete sum_image;
delete[] data;
*/
}

I get

Error in <TGaxis::PaintAxis>: wmin (0.000000) == wmax (0.000000)
Error in <TGaxis::PaintAxis>: wmin (0.000000) == wmax (0.000000)

And the attached image.

do you get the same ?


yes and if you look in the framebuffer the stored images have random noise.
edit: I mean random hits. In the sum image there should be the sum of all acquired frames

I have tried to use CopyArea. Seems to me it is working:

{
   TImage *img = TImage::Open("rose512.jpg");

   if (!img) {
      printf("Could not create an image... exit\n");
      return;
   }

   img->SetConstRatio(0);
   img->SetImageQuality(TAttImage::kImgBest);

   c1 = new TCanvas("c1", "c1", 760, 900);
   c1->Divide(1, 2);
   c1->cd(1);
   img->Draw();

   TImage *img2 = TImage::Open("rose512.jpg");
   img->CopyArea(img2,100,100,200,200,0,0);
   c1->cd(2);
   img2->Draw();

}

I get a copy of the 200x200 square at position 100,100 in img, in img2 at position 0,0

I found it, it was a very stupid mistake in my code.
I chose to CopyArea from 1000,1000 to 1000,1000! of course this does not work.