2012-02-28 12 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 컨트롤에서 이미지를 가져 오는 세 번째 시도입니다. 처음에 나는 src,이 게임에 나에게 나쁜 이미지를 보냈다. 그런 다음 자바 스크립트를 삽입하려고했지만 성공하지 못했습니다. 이제 나는 이것을 시도하고있다. 그것은 이미지를 찾고 있지만 비트 맵으로 변환 할 수 없습니다.WebBrowser에서 이미지 복사

어떤 도움이 필요합니까?

편집 : 난 그냥 시각적 표현을 볼 수있는 양식에 문제의 웹 브라우저 컨트롤을 넣어, 내가 끌어 노력하고 이미지가로드되지 않습니다 코드는 C#을에게

편집 편집을합니다. 어쩌면 이것이 문제일까요?

+0

어떤 언어입니까? 제대로 태그를 달아주세요. – vulkanino

+0

죄송합니다. C#. 그것을 – TheGateKeeper

+0

가능한 중복 [인터넷에서 그들을 redownloading없이 webbrowser 컨트롤에 이미지를 저장] (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에 의해 이미지를 얻으려고했다는 질문에 이미 언급했는데, 이것은 내 경우에는 효과가 없다. 웹 브라우저 컨트롤에 표시된 이미지를 가져와야합니다. – TheGateKeeper

관련 문제