0

My aim is to extract an image from a loaded webbrowser control.

// get the image link from the image element ID.
string imageLink = wbVideos.Document.GetElementById("sbvdcapimg").GetAttribute("src").ToString();

//Download the image into a bitmap
Bitmap image = new Bitmap(new System.IO.MemoryStream(new System.Net.WebClient().DownloadData(imageLink)));

so the code works for most pictures, but i receive me a format error when i use it with the link below.

The error is thrown when i parse this link into my code: "http://www.swagbucks.com/?cmd=cp-get-captcha-image&ctype=1&tai=478817685&sid=0.4015013770493371"

(Please Note to view the image you need to login!)

Notice how the image does not end in a extension, this is most likely causing the error.

Example of the extracted link: enter image description here

so, my question, how can i make my code accept this link as a valid image file?

Msegling
  • 365
  • 3
  • 12
  • 1
    When I navigate to http://www.swagbucks.com/?cmd=cp-get-captcha-image&ctype=1&tai=478817685&sid=0.4015013770493371 I get a blank page with `Content-Type: text/plain` response header. No image at all. So I don't know what exactly are you expecting when you feed blank response to a `System.Drawing.Bitmap` instance? Of course that it will fail. What dynamically generated image are you talking about? Where can we see it? The url you provided is completely broken, so no wonders why your code doesn't work. Maybe you could contact the authors of this url that you are trying to retrieve an image from. – Darin Dimitrov Dec 30 '13 at 14:53
  • Yes, you can, but I can't see you anywhere in your `WebClient` example to be providing such username and password information. Maybe you expected that the `WebClient` class will know your username and password and automatically provide it for you when making the request? – Darin Dimitrov Dec 30 '13 at 15:26
  • I Believe the Site checks that you have a valid cookie before displaying the image. In my webbrowser i first login, then i navigate to the page that contains the image. – Msegling Dec 30 '13 at 15:32

0 Answers0