Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# Streams Help

  • 17-09-2008 09:40PM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    I've been playing around with trying to get a stream to display on a windows form but having soooooo much trouble, i'm not sure when to go after this:
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
    req.Credentials = new NetworkCredential(username, password);
    WebResponse resp = req.GetResponse();
    Stream stream = resp.GetResponseStream();
    
    How do i take the stream and show it on a windows form, in a picture box or a panel!?
    Any help much appreciated as always.
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Quickly
    StreamReader reader = new StreamReader(response.GetResponseStream());
    panel1.text = reader.ReadToEnd();
    


  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Ginger wrote: »
    Quickly
    StreamReader reader = new StreamReader(response.GetResponseStream());
    panel1.text = reader.ReadToEnd();
    
    That wont work for a video stream though, i can capture a still jpg image from the camera buy doing:
    WebResponse resp = req.GetResponse();
    Stream stream = resp.GetResponseStream();
    
    while ((read = stream.Read(buffer, total, 1000)) != 0)
    {
         total += read;
    }
    
    Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));
    
    Having trouble getting and displaying a constent stream, the code below retreives the video stream but dispite all my efforts i can't get it to display in a picturebox or pane!??
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
    req.Credentials = new NetworkCredential(username, password);
    WebResponse resp = req.GetResponse();
    Stream stream = resp.GetResponseStream();
    


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    You didnt say it was an image

    Fire it into a byte array and then write the file out as a jpg which you can then load into your panel etc

    byte[] response = resp.ToArray();


    BUT...

    Havent tested this but should do it...

    using System.Drawing

    PictureBox1.Image = Image.FromStream(resp);

    //resp is your memory stream from your HttpWebResponse


    Edit: its a video stream you want to display.. will come back to you


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger




Advertisement