While capturing screen error occurs: Raised Exception class Eoutofresources with message

Asked

Viewed 394 times

1

I am using Embarcadero RAD Studio 2010 Delphi.

I was doing tests to capture the screen images of other computers via sockets. Then I came across an error while capturing the screen and turning to JPG (or even recording as default BMP), after about 10 seconds - running a TTimer 400 interval error occurs:

[nameProjeto.exe] Raised Exception class Eoutofresources with message 'Insufficient storage space to process this command.'.

When you see the Timer event code, you will see that (for testing) I am just running the function CapturaTelaJpg without saving it in anything (but it saves perfectly), and even then the error occurs after the 10 seconds.

function CapturaTelaJpg: TJpegImage;
var
  dc : hdc;
  cv : TCanvas;
  aux : TBitmap;
begin

  Result := TJPEGImage.Create;

  aux := TBitmap.Create;
  aux.Height := Screen.Height;
  aux.Width := Screen.Width;

  dc := GetDC(0);
  cv := TCanvas.Create;
  cv.Handle := dc;

  //--Define o tamanho da imagem
  aux.Canvas.CopyRect(Rect(0,0,Screen.Width,Screen.Height),cv,
  Rect(0,0,Screen.Width,Screen.Height));
  cv.Free;
  cv := nil;
  ReleaseDC(0,dc);

  //-- Compacta o BMP para JPEG
  Result.Assign(aux);
  aux.Free;
  aux := nil;
  Result.Compress;

end;

Timer1 400-fold

procedure TfrmMonitorando.Timer1Timer(Sender: TObject);
begin

  CapturaTelaJpg; // 10s depois, ocorre o erro colocando ou não numa variável

end;
  • Come on, first perform the procedure on your own PC, if the error occurs it has nothing to do with network, if it does not occur your problem is in the memory size used by client side! 2nd timer with interval 400 ????????????? ctz of that 400 is less than half a second, ie your timer is every second calling the same function 2 times.

  • No matter the interval the error keeps occurring, it just takes a little longer to appear. And the test performed was not done on the network, is on my pc. For some reason Function is not downloaded from memory. Even if I put interval := 5000, the error appears anyway. It’s actually, every time he runs Function, he creates a Tjpegimage, right? Then I’d have to take that returned object out of memory. I’m not very experienced. I wanted to know how to recall this return.

  • Put a Breakpoint in the function and debug it and tell where the bug is! Press F8 and see how far it can go!

  • No no. you don’t understand. Function works perfectly. what’s going on is that it’s stacking memory.

1 answer

2


Friend, create a new project, put in function and declare in uses JPEG.

Now add a component TImage, a component TTimer with Interval 400.

In the component TTimer apply the function call but this way:

procedure frmTeste.Timer1Timer(Sender: TObject);
begin
  Image1.Picture.Assign(CapturaTelaJpg);
end;

Ran flawlessly for more than 5 minutes!

The problem is that you called the function and did not use its contents!

Note, I didn’t modify anything, I just copied your function and pasted! The only change was in the call!

Edit:

Come on, at the beginning of your add function:

//Aqui adicionamos uma tentativa de eliminar resto de memória!
  if Result <> nil then
    Result := Nil;

Comment or remove the line Result.Compress;

PS: Don’t change anything else in your role! Rest is working well!

  • While the app runs, you can move the form and watch the function running and updating Timage in real time!

  • An additional, I asked to create a new project because, with the ZERO project here was no error, if there is error you should look in the project if there is something else calling the function!

  • Friend, I did as you said. There is no mistake, but it is because the project is very light now. See in your task manager its memory consumption rising infinitely.

  • Negative, here the consumption was paralyzed by 60mb, it is understandable the 60mb because my screen is giant and be using BMP!

  • and have you tested with jpeg? here the consumption is going up no matter the range it stacks the memory in the line "Result.Compress" (in vdd qnd the Function brings the return)

  • I edited the answer, downloaded my memory consumption, however high consumption can be the version of Delphi or processor architecture (mine and your)

  • Ok worked (but the result := nil n makes a difference). but I need to compress the image to send faster over the network. Or there is another way more "usual"?

  • 1

    JPEG is already compressed, I don’t know another method! The result := nil is functional if your function chokes! is a Control!

  • Oh yes. I got it. obg. I did it another way here and tmbm worked. I did it like Procedure and put a jpg per parameter and then gave a . free in it and was also. thanks for the clarification

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.