I'm working with Delphi 7 and I have to generate a lot of bitmaps from a FlashMovie embedded in my Delphi application. Definition of the pictures is 1010x720.
When I generate more than 6000 pictures (the number is different everytime), I get an EOutOfResources exception. I've looked around and it seems that it could come from a lack of available handles.
Here is the code:
var
FFlashPlayerControlExport:TFlashPlayerControl;
Bmp:TBitmap;
pPNG:TPNGObject;
begin
Bmp := FFlashPlayerControlExport.CreateFrameBitmap;
Bmp.Width := StrToInt(aArgs[5]);
Bmp.Height := StrToInt(aArgs[6]);
pPNG := TPNGObject.Create;
pPNG.Assign(Bmp);
pPNG.SaveToFile(sFileName);
pPNG.Free;
DeleteObject(Bmp.Handle);
Bmp.Free;
end;
I have tried CloseHandle(Bmp.Handle) just before Bmp.Free but I'm getting an EExternalException.
Thank you all for your help!
UPDATE 06 Dec 2012 :
Thanks to Arioch'The's answer, I tried to set the Width and Height of FFlashPlayerControlExport directly instead of using Bmp.Width and Bmp.Height It helped because now I don't get a EOutOfResources exception but the CreateFrameBitmap saves an all-black picture after a while.
FlashPlayerControl is still running because I see the picture on the screen.
Code update :
var
FFlashPlayerControlExport:TFlashPlayerControl;
Bmp:TBitmap;
pPNG:TPNGObject;
begin
FFlashPlayerControlExport.Width := StrToInt(aArgs[5]);
FFlashPlayerControlExport.Height := StrToInt(aArgs[6]);
Bmp := FFlashPlayerControlExport.CreateFrameBitmap;
pPNG := TPNGObject.Create;
pPNG.Assign(Bmp);
pPNG.SaveToFile(sFileName);
pPNG.Free;
Bmp.Free;
end;
UPDATE 20 Dec 2012 :
After contacting the FlashPlayerControl developper team, I found out that the bitmaps become black when the application reaches 10.000 GDI objects. They provided an effective help with my problem, contacting them is efficient :)
I eventually found out that the GDI objects leak comes from another parallel part of my code. This subject is close :)