能不能帮我把这一小段的C#代码变成delphi的
代码如下
public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
{
HTMLDocument doc = (HTMLDocument)wbMail.Document.DomDocument;
HTMLBody body = (HTMLBody)doc.body;
IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
IHTMLControlElement Img;
if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
{
int ImgNum = GetPicIndex(wbMail, Src,Alt);
if (ImgNum == -1) return null;
Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
}
else
Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement; rang.add(Img);
rang.execCommand("Copy", false, null);
Image RegImg = Clipboard.GetImage();
Clipboard.Clear();
return RegImg;
} public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt)
{
int imgnum = -1;
for (int i = 0; i < wbMail.Document.Images.Count; i++) //获取所有的Image元素
{
IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;
if (Alt == "")
{
if (img.src.Contains(Src)) return i;
}
else
{
if (!string.IsNullOrEmpty(img.alt))
{
if (img.alt.Contains(Alt)) return i;
}
}
}
return imgnum;
}如看不清可在这个地址看:http://www.cnblogs.com/hobe/archive/2007/03/14/674292.html
代码如下
public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
{
HTMLDocument doc = (HTMLDocument)wbMail.Document.DomDocument;
HTMLBody body = (HTMLBody)doc.body;
IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
IHTMLControlElement Img;
if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
{
int ImgNum = GetPicIndex(wbMail, Src,Alt);
if (ImgNum == -1) return null;
Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
}
else
Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement; rang.add(Img);
rang.execCommand("Copy", false, null);
Image RegImg = Clipboard.GetImage();
Clipboard.Clear();
return RegImg;
} public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt)
{
int imgnum = -1;
for (int i = 0; i < wbMail.Document.Images.Count; i++) //获取所有的Image元素
{
IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;
if (Alt == "")
{
if (img.src.Contains(Src)) return i;
}
else
{
if (!string.IsNullOrEmpty(img.alt))
{
if (img.alt.Contains(Alt)) return i;
}
}
}
return imgnum;
}如看不清可在这个地址看:http://www.cnblogs.com/hobe/archive/2007/03/14/674292.html
区别不大
uses MSHTML, Clipbrd;function GetPicIndex(wbMail: TWebBrowser; Src: string; Alt: string): Integer;
var
doc: IHTMLDocument2;
I: Integer;
img: IHTMLImgElement;
begin
doc := wbMail.Document as IHTMLDocument2;
Result := -1;
for I := 0 to doc.images.length - 1 do
begin
img := doc.images.item(I, EmptyParam) as IHTMLImgElement;
if Alt = '' then
begin
if SameText(img.src, Src) then
begin
Result := I;
Break;
end;
end else
begin
if SameText(img.alt, Alt) then
begin
Result := I;
Break;
end;
end;
end;
end;function GetRegCodePic(wbMail: TWebBrowser;
ImgName: string; Src: string; Alt: string): TGraphic;
var
doc: IHTMLDocument2;
body: IHTMLElement2;
rang: IHTMLControlRange;
Img: IHTMLControlElement;
ImgNum: Integer;
begin
Result := nil;
doc := wbMail.Document as IHTMLDocument2;
body := doc.body as IHTMLElement2;
rang := body.createControlRange() as IHTMLControlRange;
if ImgName = '' then //如果没有图片的名字,通过Src或Alt中的关键字来取
begin
ImgNum := GetPicIndex(wbMail, Src,Alt);
if ImgNum < 0 then Exit;
Img := doc.images.item(ImgNum, EmptyParam) as IHTMLControlElement;
end else Img := doc.images.item(ImgName, EmptyParam) as IHTMLControlElement;
rang.add(Img);
rang.execCommand('Copy', False, EmptyParam);
if Clipboard.HasFormat(CF_BITMAP) then
begin
Result := TBitmap.Create;
Result.Assign(Clipboard);
end else if Clipboard.HasFormat(CF_METAFILEPICT) then
begin
Result := TMetafile.Create;
Result.Assign(Clipboard);
end;
Clipboard.Clear();
end;