长时间调用屏幕截取出错 Out of resources
ahjoe 2010-11-23 02:33:53 截取屏幕画面保存到 Abmp 中。
function CaptureScreen4(Abmp: TBitmap): Boolean;
var
bmp: TBitmap;
adc: HDC;
begin
Result := False;
adc := GetDC(0);
if adc <> 0 then
try
bmp := TBitmap.Create();
bmp.Width := Screen.Width;
bmp.Height := Screen.Height;
Result := BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
adc, 0, 0, SRCCOPY);
if Result then
begin
Abmp.Width := bmp.Width;
Abmp.Height := bmp.Height;
Abmp.Canvas.Draw(0, 0, bmp);
end;
finally
bmp.Free();
ReleaseDC(0, adc);
end;
end;
大概每秒钟两次,运行2、3小时后,出错 Out of resources,怀疑是TBitmap类型造成的Device context句柄泄漏