Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Spara en websida som en JPEG-fil
|
Kategori: Grafik
Inlagt: 2005-03-17
Läst: 1398
Inlagt av: Staffan Berg
|
Beskrivning |
Detta exempel demonstrerar hur du genom en TWebBrowser kan spara ned en websida som en bild i jpg-format.
|
Kod |
procedure GenerateJPEGfromBrowser(browser: iWebBrowser2; jpegFQFilename: string ; srcHeight: integer; srcWidth: integer; tarHeight: integer; tarWidth: integer);var sourceDrawRect: TRect; targetDrawRect: TRect; sourceBitmap : TBitmap; targetBitmap : TBitmap; aJPG : TJPEGImage; aViewObject : IViewObject;begin // GenerateJPEGfromBrowser sourceBitmap := TBitmap.Create; targetBitmap := TBitmap.Create; aJPG := TJPEGImage.Create; try try sourceDrawRect := Rect(0, 0, srcWidth, srcHeight); sourceBitmap.Width := srcWidth; sourceBitmap.Height := srcHeight; aViewObject := browser as IViewObject; if aViewObject=nil then Exit; OleCheck(aViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Form1.Handle, sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0)); // Resize the src bitmap to the target bitmap // Need to make thumbnails instead of full size? // set the target size here.. 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 aJPG.Assign(targetBitmap); aJPG.SaveToFile(jpegFQFilename) finally aJPG.Free; sourceBitmap.Free; targetBitmap.Free end; { try } except // error handler code end; // tryend; // GenerateJPEGfromBrowser procedure TForm1.Button2Click(Sender: TObject);var IDoc1: IHTMLDocument2; Web : iWebBrowser2; tmpX, tmpY : integer;begin // TForm1.Button2Click with WebBrowser1 do begin Document.QueryInterface(IHTMLDocument2, IDoc1); Web := ControlInterface; tmpX := Height; tmpY := Width; Height := OleObject.Document.ParentWindow.Screen.Height; Width := OleObject.Document.ParentWindow.Screen.Width; GenerateJPEGfromBrowser(Web, '.\test.jpg', Height, Width, Height, Width); Height := tmpX; Width := tmpY; Image1.Picture.LoadFromFile('.\test.jpg') end; // with WebBrowser1 end; // TForm1.Button2Click
|
|
|