简体   繁体   中英

How show image(s) from Stream(Responce) in a PictureBox - Specific URL

here is my codes :

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.flowercity.com/");
    req.Method = "GET";
    req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    req.ContentType = "text/html; charset=utf-8";
    req.Timeout = 25000;

    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

    Stream Stream = res.GetResponseStream();
    StreamReader reader = new StreamReader(Stream);
    string reader_str = reader.ReadToEnd();

how can i grab loaded images in Stream and show them one by one in a PictureBox?

Edit 1 :
please see my url, it's not an image, it's a web site and we have a web site in Stream.
so the codes below does not work :

    Image img = Image.FromStream(Stream);
    PictureBox1.Image = img;

Edit 2 :
i can not use HtmlAgilityPack for getting image urls .
there is no specific url for every image and need to show previous loaded images in stream .

As stated in the comment by vcsjones, your stream is that of the index page of the website. Within it are image tags . Like your browser does for you when you navigate to the site in question, you need to download the images separately.

The most reliable method for doing that is probably to use regular expressions to search the webpage (the one you're loading in your example code) for those links. You can obviously try to load the page as an XML document but XML parsers are very strict on validity. Most webpage authors unfortunately aren't so a more "loose" search of the webpage for your links probably works best.

Your code should work if you feed it a direct image link. Your challenge now is to get those direct links from the page you're loading.

Edit

Your webpage looks something like this:

<html>
<title>welcome to the flower page</title>
<img src="flower.jpg"/>
</html>

(shortened for simplicity's sake)

You need to read through the text you are getting to find where the images are stored on the webserver and then open a separate http connection to download each image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM