给出此错误的程序。有时立即,有时在短时间内
http://www1.datafilehost.com/d/39f524c0 线程在某些 try finally 块中暂停
资源:
http://www1.datafilehost.com/d/1cae7b24 EOufOfResources 调试期间
我很抱歉英语不好。我有以下问题:我尝试制作 5 fps 的屏幕截图并在其上绘制光标图标,在 PNG 中重新编码 BMP 并通过阻塞套接字 Indy 通过网络发送它。发送按比例压缩并放置在主窗体上的 TImage(桌面图像)上的屏幕截图后。如果我在计时器中执行所有这些操作 - 如果我在 Synchronize() 中执行所有这些代码,则一切正常,它也可以正常工作,但它会导致界面冻结,我想摆脱它,并做所以在线程中的 PNG 压缩中,现在我尝试打破几个 Synchronize() 来查找错误(我收到错误 EOutOfResources),但我做不到。请帮忙。这是我的代码:
TCaptureThread = class(TThread)
private
bmp: TBitmap;
DC: HDC;
h:hwnd;
thumbRect : TRect;
maxWidth, maxHeight:integer;
png:TPNGImage;
Stream:TMemoryStream;
RecBlock:TCommBlock;
r: TRect;
CI: TCursorInfo;
Icon: TIcon;
II: TIconInfo;
commblock:TCommblock;
procedure showthumb;
procedure send;
procedure stretch;
procedure getscreen;
procedure fixsize;
protected
procedure Execute; override;
constructor Create(CreateSuspended: Boolean);
destructor destroy; override;
end;
constructor TCaptureThread.Create(CreateSuspended: Boolean);
begin
bmp:=TBitmap.Create;
Stream:=TMemoryStream.Create;
png:=TPNGImage.Create;
Icon := TIcon.Create;
inherited Create(CreateSuspended);
end;
destructor TCaptureThread.destroy;
begin
png.Free;
bmp.Free;
Icon.Free;
stream.Free;
inherited;
end;
procedure TCaptureThread.Execute;
begin
inherited;
while not Terminated do
begin
Synchronize(fixsize);
Synchronize(getscreen);
r := bmp.Canvas.ClipRect;
try
CI.cbSize := SizeOf(CI);
if GetCursorInfo(CI) then
if CI.Flags = CURSOR_SHOWING then
begin
Icon.Handle := CopyIcon(CI.hCursor);
if GetIconInfo(Icon.Handle, II) then
begin
bmp.Canvas.Draw(
ci.ptScreenPos.x - Integer(II.xHotspot) - r.Left - Form4.Left,
ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top - Form4.Top,
Icon
);
end;
end;
finally
end;
try
png.Assign(bmp);
png.CompressionLevel := 9;
png.SaveToStream(stream);
stream.Position :=0;
Recblock.Command :='STREAM';
Recblock.Msg :='';
Recblock.NameFrom := MyName;
Synchronize(send);
finally
end;
try
thumbRect.Left := 0;
thumbRect.Top := 0;
if bmp.Width > bmp.Height then
begin
thumbRect.Right := maxWidth;
thumbRect.Bottom := (maxWidth * bmp.Height) div bmp.Width;
end
else
begin
thumbRect.Bottom := maxHeight;
thumbRect.Right := (maxHeight * bmp.Width) div bmp.Height;
end;
Synchronize(stretch);
bmp.Width := thumbRect.Right;
bmp.Height := thumbRect.Bottom;
Synchronize(showthumb);
finally
end;
sleep(200);
end;
end;
procedure TCaptureThread.getscreen;
begin
DC:=GetDC(0);
bitblt(bmp.Canvas.Handle, 0, 0, Form4.Width+Form4.Left, Form4.Height+Form4.Top,
DC, Form4.Left, Form4.Top, SRCCOPY);
ReleaseDC(0, DC);
end;
procedure TCaptureThread.fixsize;
begin
maxWidth := Form1.DesktopImage.Width;
maxHeight := Form1.DesktopImage.Height;
bmp.Height:=Form4.Height;
bmp.Width:=Form4.Width;
end;
procedure TCaptureThread.send;
begin
Form1.Streamclient.IOHandler.Write(RawToBytes(Recblock,sizeof(recblock)),sizeof(recblock));
Form1.Streamclient.IOHandler.Write(stream,stream.Size,true);
end;
procedure TCaptureThread.showthumb;
begin
Form1.DesktopImage.Picture.Assign(bmp);
end;
procedure TCaptureThread.stretch;
begin
SetStretchBltMode(bmp.Canvas.Handle, HALFTONE);
StretchBlt(bmp.Canvas.Handle,0,0,thumbRect.Right,thumbRect.Bottom,bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,SRCCOPY);
end;