Stream from IP cam C#

霸气de小男生 提交于 2019-12-04 13:53:26

It looks like your loop for reading from the response stream is incorrect. You only ever get one stream from a response, and it will have multiple images on it.

It is likely that you can't pass the response stream to Image.FromStream directly - the images are probably encoded in a multi-part response that separates the images with textual delimiters. You can learn more about the format of multi-part responses at RFC2046.

using (webRes = webReq.GetResponse())
{
    using (sr = webRes.GetResponseStream())
    {
        // continuously read images from the response stream until error
        while (true)
        {
            try
            {
                // note: the line below probably won't work, you may need to parse
                // the next image from the multi-part response stream manually
                image.Image = Image.FromStream(sr);


                // if the above doesn't work, then do something like this:
                // var imageBytes = ParseNextImage(sr);
                // var memoryStream = new MemoryStream(imageBytes);
                // image.Image = Image.FromStream(memoryStream);
            }
            catch(Exception e)
            {
                Console.WriteLine("Aborting read from response stream due to error {0}", e);
                break;
            }
        }
    }
}

Does the camUrl return an image?

Try to debug sr = webRes.GetResponseStream() and if it is not null, try image.Invalidate() or image.Update()

More information about invalidate, update and refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!