Results 1 to 6 of 6

Thread: Image from HttpWebResponse makes Argument exception error

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2014
    Posts
    32

    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?

  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Norway; Haugesund
    Posts
    39

    Re: Image from HttpWebResponse makes Argument exception error

    Quote Originally Posted by stephenpark View Post

    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
    Last edited by Frekvens1; Jan 31st, 2015 at 06:34 AM. Reason: Spellings

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2014
    Posts
    32

    Re: Image from HttpWebResponse makes Argument exception error

    Quote Originally Posted by Frekvens1 View Post
    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...!

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,390

    Re: Image from HttpWebResponse makes Argument exception error

    Can you post a valid url to test agasint. Saves me working blind.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2014
    Posts
    32

    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.
    Last edited by stephenpark; Jan 31st, 2015 at 11:36 PM.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,390

    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"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width