Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# Streams Help

Options
  • 17-09-2008 9:40pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    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 Posts: 2,931 ✭✭✭Ginger


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


  • Registered Users Posts: 1,987 ✭✭✭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 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 Posts: 2,931 ✭✭✭Ginger




Advertisement