Image from HttpWebResponse makes Argument exception error
Hi, I'm trying to get single image stream from IP camera, and it works with other cameras
and using web browser, image displayed correctly but not with my code.
This is my code:
Code:
Private Sub obtainImage()
Dim url As String = "http://" + CAMAddr + "/cgi-bin/fwcamimg.cgi?FwModID=0&PortId=1&FwCgiVer=0x0001"
Dim request As Net.HttpWebRequest
Try
request = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
Catch ex As Exception
Exit Sub
End Try
request.KeepAlive = False
' This is method A
'Dim webClient As New System.Net.WebClient
'Dim bytes() As Byte = webClient.DownloadData(url)
'Dim stream As New IO.MemoryStream(bytes)
'Dim Img As Image = Image.FromStream(stream)
' This is method B
Dim response As Net.HttpWebResponse = DirectCast(request.GetResponse, Net.HttpWebResponse)
Dim img As Image = Image.FromStream(response.GetResponseStream)
If Not PictureBox1 Is Nothing Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureShow(PictureBox1, img)
End If
response.Close()
request.Abort()
response = Nothing
request = Nothing
End Sub
When I use other cameras, this works perfectly.
I use new camera, and this routine does not work, but, with webbrowser, above url works
nicely... when I use same url string with webbrowser control, image is displayed and
webbrowser.documenttype shows it is JPEG format.
But above code, with blue line, it makes Argument exception error.
Anybody can help me?
Re: Image from HttpWebResponse makes Argument exception error
Quote:
Originally Posted by
stephenpark
Code:
' This is method B
Dim response As Net.HttpWebResponse = DirectCast(request.GetResponse, Net.HttpWebResponse)
Dim img As Image = Image.FromStream(response.GetResponseStream)
If Not PictureBox1 Is Nothing Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureShow(PictureBox1, img)
End If
But above code, with blue line, it makes Argument exception error.
I'm not an expert at streams, but the above code looks like it should work. The Argument exception is probably there because you don't have enough arguments? If you say the code breaks when the picturebox retrieves the data, this could maybe help.
Code:
Dim img As Image = Image.FromStream(response.GetResponseStream, True, True)
There is no guarantee it will work, as I can't test your code (I don't have all your references to play around with your code). I'm actually curious about how to fix this problem myself. Hopefully someone with more knowledge will soon approach!
- Frek
Re: Image from HttpWebResponse makes Argument exception error
Quote:
Originally Posted by
Frekvens1
I'm not an expert at streams, but the above code looks like it should work. The Argument exception is probably there because you don't have enough arguments? If you say the code breaks when the picturebox retrieves the data, this could maybe help.
Code:
Dim img As Image = Image.FromStream(response.GetResponseStream, True, True)
There is no guarantee it will work, as I can't test your code (I don't have all your references to play around with your code). I'm actually curious about how to fix this problem myself. Hopefully someone with more knowledge will soon approach!
- Frek
Thanks for your interest, Frek.
However, another two arguments from FromStream(response.GetResponsStream, True, True) does not
do anything. I've tried it already.
Even I make FileStream, using byte array and convert GetResponsStream to file, it is only 24 byte,
and looks like there is no header information. However what I don't understand is that if I just use
WebBrowser control and use url for exactly same url as in my code, it shows image without any problem. Maybe there is something other reason which prevent change http stream to image.
It is really weird and headache...!
Re: Image from HttpWebResponse makes Argument exception error
Can you post a valid url to test agasint. Saves me working blind.
Re: Image from HttpWebResponse makes Argument exception error
You can use this url:
http://commaxmall.iptime.org:9080/cg...wCgiVer=0x0001
You can use this exact url on the code. With internet explorer, you can see picture.
This is temporary address, when this problem solved, will close connection.
Re: Image from HttpWebResponse makes Argument exception error
No magic.....
Code:
Me.PictureBox1.ImageLocation = "http://commaxmall.iptime.org:9080/cgi-bin/fwcamimg.cgi?FwModId=0&PortId=1&FwCgiVer=0x0001"