PrintWindow函数截取网页图片 请高手帮忙
- Delphi(Pascal) code
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Timer1: TTimer; Button1: TButton; procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; function EnumWindowsProc(AhWnd:LongInt;AForm:TForm1):boolean;stdcall; Function PrintWindow(SourceWindow: hwnd; Destination: hdc; nFlags: cardinal): bool; stdcall; external 'user32.dll' name 'PrintWindow';implementation{$R *.dfm}function EnumWindowsProc(AhWnd:LongInt;AForm:TForm1):boolean;var lpszWindowText:array[0..254] of char; Bitmap: TBitmap; rec : TRect; //x, y : Integer;begin GetWindowText(AhWnd,lpszWindowText,254); if pos('百度搜索',StrPas(lpszWindowText))>0 then begin GetWindowRect(AhWnd, rec); //获取到窗口的矩形 Bitmap := TBitmap.Create; try Bitmap.Width := rec.Right - rec.Left; Bitmap.Height := rec.Bottom - rec.Top; Bitmap.PixelFormat := pf24bit; PrintWindow(AhWnd, Bitmap.Canvas.Handle, 0); Bitmap.SaveToFile(FormatDatetime('yyyymmddhhnnss', Now())+'led.bmp'); finally Bitmap.Free; end; end; Result:=True;end;procedure TForm1.Timer1Timer(Sender: TObject);beginEnumWindows(@EnumWindowsProc,LongInt(self));end;procedure TForm1.Button1Click(Sender: TObject);beginTimer1Timer(nil);end;end.全部代码在上面。问题是截图的时候有时会出现下半截黑色,或者全部黑色的。我猜可能是网页刷新导致的。如何获得截出来的图片是完整的,而不存在有黑色的?请高手帮忙,谢谢了。
[解决办法]
不懂~帮顶~蹭分~
[解决办法]
来关注下
[解决办法]
PrintWindow截可能会有问题的,你换其他的方法试下!
[解决办法]
怎么解决的,分享一下。
[解决办法]
mark
[解决办法]
顶顶,学习学习一下>>>>>>>>>>>>>>>>>>
[解决办法]
Lz分享一下~~