Hello,
This code give jpg from a MJPEG stream from an IP camera DCS-900 in the
folder "c:\_bin". The only and probably the most important part is I
can't see the JPG. It is probably an encoding error. So having spent
the best part ofthe last 5 days trying to fix it, can somebody please
help me find the problem?
Imports System.Net.WebRequest
Imports System.Net.WebResponse
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.Data.SqlClient
Module Module1
Sub Main()
Dim myWebRequest As Net.WebRequest =
Net.WebRequest.Create("http://192.168.2.10/video.cgi")
' Send the 'WebRequest' and wait for response.
Dim myWebResponse As Net.WebResponse =
myWebRequest.GetResponse()
' Call method 'GetResponseStream' to obtain stream associated
with the response object
Dim ReceiveStream As IO.Stream =
myWebResponse.GetResponseStream()
' Pipe the stream to a higher level stream reader with the
required encoding format.
Dim encode As System.Text.UTF8Encoding =
CType(System.Text.Encoding.GetEncoding("utf-8"),
System.Text.UTF8Encoding)
' Pipe the stream to a higher level stream reader with the
required encoding format.
Dim readStream As New StreamReader(ReceiveStream, encode)
'Console.WriteLine(ControlChars.Cr + "Response stream
received")
Dim read(1) As [Char]
Dim count As Integer = readStream.Read(read, 0, 1)
Dim b_doTheJpg As Boolean = False
Dim s_jpg As String = ""
Dim s_string As String = ""
Dim s_fileToSave As String = ""
Dim i_line As Integer = 0
Dim i_file As Integer = 0
Dim i_whereToStart As Integer = 0
Dim i_lenOfTheChar As Integer = 0
Dim b_byte() As Byte
While count 0
Dim str As New [String](read, 0, count)
count = readStream.Read(read, 0, 1)
s_string = s_string & str
If Len(s_string) 18 Then
s_string = Mid(s_string, 2, Len(s_string) - 1)
End If
If CBool(InStr(s_string, "--video boundary--",
CompareMethod.Text)) Then
If CBool(Len(s_fileToSave) 0) Then
s_fileToSave = Mid(s_fileToSave, 1,
Len(s_fileToSave) - 18)
Dim strFilename As String = "C:\_bin\" & i_file &
".jpg"
i_file = i_file + 1
Dim fsStream As StreamWriter
fsStream = File.CreateText(strFilename)
fsStream.WriteLine(Trim(s_fileToSave))
fsStream.Close()
b_doTheJpg = False
s_fileToSave = ""
End If
End If
If b_doTheJpg = True Then
s_fileToSave = s_fileToSave & str
End If
If CBool(InStr(s_string, "t-type: image/jpeg",
CompareMethod.Text)) Then
b_doTheJpg = True
End If
End While
'Console.WriteLine("")
' Release the resources of stream object.
readStream.Close()
' Release the resources of response object.
myWebResponse.Close()
End Sub
End Module