delphi读取webbrowse中的图片显示在Image中


本文整理自网络,侵删。

 

unit Unit11;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls;

type
  TForm11 = class(TForm)
    btn1: TButton;
    img1: TImage;
    wb1: TWebBrowser;
    btn2: TButton;
    mmo1: TMemo;
    edt1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form11: TForm11;

implementation
uses ActiveX, wininet, mshtml, Clipbrd;
{$R *.dfm}

procedure DomImg2Image(id:string; wb:TWebBrowser; img:TImage );
var
  rang:IHTMLControlRange;
begin
  rang:=((IHTMLDocument2(wb.Document).body as HTMLBody).createControlRange)as
    IHTMLControlRange;
  rang.add(IHTMLDocument2(wb.Document).images.item(id,EmptyParam)as
    IHTMLControlElement);
  rang.execCommand('Copy',False,0);
  img.Picture.Assign(ClipBoard);
end;

procedure TForm11.btn1Click(Sender: TObject);
var
  i:Integer;
  rang:IHTMLControlRange;
begin
  //遍历图片元素, 在memo中显示Img的ID和src属性
  mmo1.clear;
  for i:= 0 to IHTMLDocument2(wb1.Document).images.length-1 do
  begin
    mmo1.lines.add((IHTMLDocument2(wb1.Document).images.item(i,EmptyParam)as
      IHTMLElement).getAttribute('id',0));
    mmo1.lines.add((IHTMLDocument2(wb1.Document).images.item(i,EmptyParam)as
      IHTMLElement).getAttribute('src',0));
  end;
end;

procedure TForm11.btn2Click(Sender: TObject);
begin
  //edt1.Text是Img的ID值, webbrowse对象, TImage
  DomImg2Image(edt1.Text, wb1, img1);
end;

procedure TForm11.FormCreate(Sender: TObject);
begin
  wb1.Navigate('http://www.3464.com/');
end;

end.

相关阅读 >>

Delphi日期函数、日期加减

Delphi 一个call应该如何写?

Delphi idhttp1 获取网页代码

Delphi android程序启动过程

Delphi 利用Delphi监视注册表的变化

Delphi 实现卸载windows应用程序(类似360软件管家-卸载程序)

Delphi实现tedit控件的外观只有一条下划线

Delphi延时4种方法

Delphi判断字符串是否为数字

Delphi 程序动态改变皮肤

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...