IE 웹브라우저(Webbrowser) 화면을 이미지로 저장하기
uses
MSHTML_TLB, JPEG, ActiveX, ComObj;
procedure generateJPEGfromBrowser(browser: iWebBrowser2; jpegFQFilename: string;
srcHeight: Integer; srcWidth: Integer; tarHeight: Integer; tarWidth: Integer);
var
sourceDrawRect: TRect;
targetDrawRect: TRect;
sourceBitmap: TBitmap;
targetBitmap: TBitmap;
jpeg: TJPEGImage;
viewObject: IViewObject;
begin
sourceBitmap := TBitmap.Create;
targetBitmap := TBitmap.Create;
jpeg := TJPEGImage.Create;
try
try
sourceDrawRect := Rect(0, 0, srcWidth, srcHeight);
sourceBitmap.Width := srcWidth;
sourceBitmap.Height := srcHeight;
viewObject := browser as IViewObject;
if viewObject = nil then
Exit;
OleCheck(viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Form1.Handle,
sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0));
// Resize the src bitmap to the target bitmap
targetDrawRect := Rect(0, 0, tarWidth, tarHeight);
targetBitmap.Height := tarHeight;
targetBitmap.Width := tarWidth;
targetBitmap.Canvas.StretchDraw(targetDrawRect, sourceBitmap);
// Create a JPEG from the Bitmap and save it
jpeg.Assign(targetBitmap);
jpeg.SaveToFile(jpegFQFilename);
finally
jpeg.Free;
sourceBitmap.Free;
targetBitmap.Free;
end;
except
// Error Code
end;
end;
procedure TForm1.btnButton1Click(Sender: TObject);
var
IDoc1: IHTMLDocument2;
Web: ShDocVW_TLB.IWebBrowser2;
tmpX, tmpY: Integer;
begin
with WebBrowser1 do
begin
Document.QueryInterface(IHTMLDocument2, iDoc1);
Web := ControlInterface;
tmpX := Height;
tmpY := Width;
TControl(WebBrowser1).Visible := Boolean(0);
// change the height and width temporary
Height := OleObject.Document.ParentWindow.Screen.Height;
Width := OleObject.Document.ParentWindow.Screen.Width;
generateJPEGfromBrowser(Web,'c: est.jpg',Height, Width, Height, Width);
Height := tmpX;
Width := tmpY;
TControl(WebBrowser1).Visible := Boolean(1);
end;
end;
'Delphi Tip > 인터넷' 카테고리의 다른 글
델파이에서 원하는 주소로 크롬실행 (0) | 2021.12.06 |
---|---|
Delphi에서 Chrome Browser 사용하기 (0) | 2021.12.05 |
Internet explorer 띄우기 (0) | 2021.12.01 |
Capture element click in Internet Explorer (0) | 2021.11.30 |
delphi로 IE 컨트롤 (0) | 2021.11.29 |
댓글