procedureGenerateJPEGfromBrowser(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
=
nilthen
Exit;

OleCheck(aViewObject.Draw(DVASPECT_CONTENT,
1
,nil,nil,
Form1.Handle,
sourceBitmap.Canvas.Handle,
@sourceDrawRect,nil,nil,
0
));

//
Resizethesrcbitmaptothetargetbitmap
//
Needtomakethumbnailsinsteadoffullsize?
//
setthetargetsizehere..targetDrawRect:=Rect(0,0,tarWidth,tarHeight);
targetBitmap.Height:
=
tarHeight;
targetBitmap.Width:
=
tarWidth;
targetBitmap.Canvas.StretchDraw(targetDrawRect,sourceBitmap);

//
CreateaJPEGfromtheBitmapandsaveitaJPG.Assign(targetBitmap);
aJPG.SaveToFile(jpegFQFilename)
finally
aJPG.Free;
sourceBitmap.Free;
targetBitmap.Free

end;
...
{try}

except
//
errorhandlercodeend;{try}

end;
...
{GenerateJPEGfromBrowser}


procedureTForm1.Button2Click(Sender:TObject);
var
IDoc1:IHTMLDocument2;
Web:iWebBrowser2;
tmpX,
tmpY:integer;

begin
...
{TForm1.Button2Click}
withWebBrowser1
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,
'
. est.jpg
'
,
Height,Width,
Height,Width);
Height:
=
tmpX;
Width:
=
tmpY;

Image1.Picture.LoadFromFile(
'
. est.jpg
'
)

end;
...
{withWebBrowser1}

end;
...
{TForm1.Button2Click}
Source code :HTTPtoJPEG.zip (3 kB)
原文连接:
http://www.delphifaq.com/fq/q2231.shtml
http://www.applevb.com