2012-02-28 4 views
1
IHTMLDocument2 doc = (IHTMLDocument2)browser.Document.DomDocument; 
    HTMLBody body = (HTMLBody)doc.body; 
    Bitmap testImage; 

    foreach (IHTMLImgElement img in doc.images) 
    { 
     if (img.src.IndexOf("some text here", 0) != -1) 
     { 
      IHTMLControlRange imgRange; 
      imgRange = (IHTMLControlRange)body.createControlRange(); 
      imgRange.add((IHTMLControlElement)img); 
      imgRange.execCommand("Copy", false, null); 
      //captchaUrl = img.GetAttribute("src"); 
      testImage = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap); 
     } 
    } 

こんにちは、これはWebBrowserコントロールから画像を取得する3番目の試みです。まずはsrcで試してみましたが、このゲームは悪いイメージです。その後、私は成功しなかったjavascriptを注入しようとしました。今私はこれを試みている。それはイメージを見つけることですが、私はビットマップに変換できません。WebBrowserの画像をコピーする

助けが必要ですか?

編集:コードは#

編集編集はC:私は視覚的な表現を見るために、フォーム上の質問にWebBrowserコントロールを入れて、私はプルしようとしているイメージがロードされていません。多分これは問題ですか?

+0

どの言語ですか?タグを付けてください。 – vulkanino

+0

申し訳ありませんが、C#。それを修正する – TheGateKeeper

+0

[インターネットからそれらを再ダウンロードせずにWebブラウザコントロールに画像を保存する](http://stackoverflow.com/questions/2566898/save-images-in-webbrowser-control-without-redownloading-them-from) -the-internet) – CodeCaster

答えて

1
/* 
* A function to get a Bitmap object directly from a web resource 
* Author: Danny Battison 
* Contact: [email protected] 
*/ 

/// <summary> 
/// Get a bitmap directly from the web 
/// </summary> 
/// <param name="URL">The URL of the image</param> 
/// <returns>A bitmap of the image requested</returns> 
public static Bitmap BitmapFromWeb(string URL) 
{ 
    try { 
     // create a web request to the url of the image 
     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL); 
     // set the method to GET to get the image 
     myRequest.Method = "GET"; 
     // get the response from the webpage 
     HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); 
     // create a bitmap from the stream of the response 
     Bitmap bmp = new Bitmap(myResponse.GetResponseStream()); 
     // close off the stream and the response 
     myResponse.Close(); 
     // return the Bitmap of the image 
     return bmp; 
    } catch (Exception ex) { 
     return null; // if for some reason we couldn't get to image, we return null 
    } 
} 
+0

私は既にURLで画像を取得しようとしているという質問に述べましたが、これは私の場合はうまくいかないのです。私は、Webブラウザコントロールで表示される画像を取得する必要があります。 – TheGateKeeper

関連する問題