以下这段代码怎么抓不了图呀?麻烦帮改一下,谢了~!
procedure TForm1.CaptureScreen;
var
img : TBitmap;
scr : TCanvas;
dc : HDC;
begin
img:= TBitmap.Create;
image1.Width:=screen.Width;
image1.Height:=screen.Height;
dc:=GetDC(0);
scr:=TCanvas.Create;
scr.Handle:=dc;
img.Canvas.CopyRect(Rect(0,0,screen.Width,screen.Height),
scr,Rect(0,0,Screen.Width,Screen.Height));
scr.Free;
releasedc(0,dc);
image1.Picture.Bitmap:=img;
image1.Width:=img.Width;
image1.Height:=img.Height;
img.Free;
end;
procedure TForm1.CaptureScreen;
var
img : TBitmap;
scr : TCanvas;
dc : HDC;
begin
img:= TBitmap.Create;
image1.Width:=screen.Width;
image1.Height:=screen.Height;
dc:=GetDC(0);
scr:=TCanvas.Create;
scr.Handle:=dc;
img.Canvas.CopyRect(Rect(0,0,screen.Width,screen.Height),
scr,Rect(0,0,Screen.Width,Screen.Height));
scr.Free;
releasedc(0,dc);
image1.Picture.Bitmap:=img;
image1.Width:=img.Width;
image1.Height:=img.Height;
img.Free;
end;
var
img : TBitmap;
scr : TCanvas;
dc : HDC;
begin
img:= TBitmap.Create;
img.Width := screen.Width;
img.Height := screen.Height;
image1.Width:=screen.Width;
image1.Height:=screen.Height;
dc:=GetDC(0);
scr:=TCanvas.Create;
scr.Handle:=dc;
img.Canvas.CopyRect(Rect(0,0,screen.Width,screen.Height),
scr,Rect(0,0,Screen.Width,Screen.Height));
scr.Free;
releasedc(0,dc);
// image1.Picture.Bitmap:=img;
image1.Picture.Bitmap.Assign(img);
image1.Width:=img.Width;
image1.Height:=img.Height;
img.Free;
end;我没调试过,你看行不行
img : TBitmap;
scr : TCanvas;
dc : HDC;
begin
img:= TBitmap.Create;
img.Width := screen.Width;
img.Height := screen.Height;
image1.Width:=screen.Width;
image1.Height:=screen.Height;
dc:=GetDC(0);
scr:=TCanvas.Create;
scr.Handle:=dc;
img.Canvas.CopyRect(Rect(0,0,screen.Width,screen.Height),
scr,Rect(0,0,Screen.Width,Screen.Height));
scr.Free;
releasedc(0,dc);
//image1.Picture.Bitmap:=img;
image1.Picture.Bitmap.Assign(img);
image1.Width:=img.Width;
image1.Height:=img.Height;
img.Free;
image1.picture:=nil//把原来的图片删除掉避免很多图片重复! end;