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

3 篇文章 0 订阅

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

==================================================

aa.html






                CAPTCHA code 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('c:\aa.html');
end;

end.


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值