2017-09-01 38 views
0

我目前正在Web应用程序上实现Camera streaming。VB Razor Web页面从页面上的远程URL呈现图像?

我有一个页面Poll_Camera.vbhtml,当访问此页面时,我希望页面只呈现从远程URL产生的图像。

每次访问URL时,都会从相机中生成新的快照图像。

这样做的最好方法是什么?

我需要每秒钟左右刷新一次图像。

我曾尝试使用

Dim CameraResponse As WebRequest = WebRequest.Create(CameraUri) 

我设法使用Javascript/Ajax来做到这一点,但因为URL包含摄像机的用户名和密码,它的效果并不理想。我也不想先将图像下载到本地目录。

另一段代码我试图在那里我得到响应的屏幕,但我觉得编码或东西可能是错误的:

Try 
    Dim request As HttpWebRequest = CType(WebRequest.Create(CameraUri), HttpWebRequest) 

    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 

    ' Get the stream associated with the response. 
    Dim receiveStream As Stream = response.GetResponseStream() 

    ' Pipes the stream to a higher level stream reader with the required encoding format. 
    Dim readStream As New StreamReader(receiveStream, Encoding.UTF8) 

    HttpContext.Current.Response.write(readStream.ReadToEnd()) 
    response.Close() 
    readStream.Close() 
Catch ex As System.Net.WebException 
    'Error in accessing the resource, handle it 
End Try 

我得到的屏幕上的以下输出

JFIF

我已经尝试设置以下,但后来我得到一个黑色的屏幕。

Response.ContentType = "image/jpeg" 
Response.Charset = "UTF-8" 

任何帮助将不胜感激。

+0

我设法用2行代码解决这个问题。将在下面发布答案。 – Deedz

回答

0

通过执行以下操作来解决上述问题。简单和简单的代码。

Try 
    Dim webClient As New System.Net.WebClient 
    Response.WriteBinary(webClient.DownloadData(siteUri), "image/jpeg") 
Catch ex As System.Net.WebException 
    'Error in accessing the resource, handle it 
End Try 

现在我可以解析加密URL我Poll_Camera.vbhtml,解密在页面上,页面将呈现相机图像为JPEG格式。