以前的笔记或摘录:存储网页为JPG
2008-12-16 16:30
281 查看
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);
Height := OleObject.Document.ParentWindow.Screen.Height;
Width := OleObject.Document.ParentWindow.Screen.Width;
generateJPEGfromBrowser(Web,'c:/test.jpg',Height, Width, Height, Width);
Height := tmpX;
Width := tmpY;
TControl(WebBrowser1).Visible := Boolean(1);
end;
end;
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);
Height := OleObject.Document.ParentWindow.Screen.Height;
Width := OleObject.Document.ParentWindow.Screen.Width;
generateJPEGfromBrowser(Web,'c:/test.jpg',Height, Width, Height, Width);
Height := tmpX;
Width := tmpY;
TControl(WebBrowser1).Visible := Boolean(1);
end;
end;
相关文章推荐
- 以前的笔记或摘录: 存储网页为HTM
- 以前的笔记或摘录:保存网页中的所有图片
- 以前的笔记或摘录:delphi IDE的快捷键
- 以前的笔记或摘录:通过Shellexecute发送带附件的邮件
- 以前的笔记或摘录:delphi关闭XP防火墙
- 以前的笔记或摘录:idsmpt身份认证相关
- 以前的笔记或摘录:WebBrowser中显示源代码
- 以前的笔记或摘录:Get Listbox Items from a TWebBrowser Document?
- 生成黑白画笔,android使用系统浏览器打开网页,将Bitmap图片存储在本地JPG文件的方法
- 以前的笔记或摘录:在TEmbeddedWB中使用自己的右键菜单
- HTML5学习笔记之客户端存储数据方法:localStorage(),sessionStorage()
- 以前看书时记得一些笔记(一),很早了,现在再看都有些看不懂了
- Android编程学习笔记 之 File数据存储
- 变量、事物、存储(今天的笔记)
- 存储基础知识学习笔记
- 【笔记】Python开发工程师要求摘录
- 转载:提高DB2数据库SQL存储过程性能学习笔记
- 菜鸟学Linux 第105篇笔记 海量存储解决
- 看书《DIV+CSS商业案例与网页布局开发精讲》_网页背景_随手笔记
- a note on distributed computing 笔记摘录