代码之家  ›  专栏  ›  技术社区  ›  Ibanez1408

从流检索图像时,参数无效

  •  0
  • Ibanez1408  · 技术社区  · 7 年前

    Dim url = "http://172.23.111.102//onvifsnapshot/media_service/snapshot?channel=1&subtype=1"
    Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
    
    Private Sub LaneCtl_Load(sender As Object, e As EventArgs) Handles Me.Load
        req.Credentials = New NetworkCredential("admin", "admin")
    End Sub
    
    Private Function CaptureImage(ByVal imagePath As String, ByVal fileName As String, CaptureNow As Boolean) As String
        Try
            If CaptureNow Then
                If (CamType = 2) Then
    
                    Dim fn = fileName
                    Dim filePath = imagePath
                    Dim file = $"{filePath}{fn}"
    
                    Dim buffer As Byte() = New Byte(99999) {}
                    Dim read As Integer = 0
                    Dim total As Integer = 0
    
                    Dim resp As WebResponse = req.GetResponse
                    Dim stream As IO.Stream = resp.GetResponseStream
                    Dim bm As Image = New Bitmap(stream)
                    bm.Save(file, Imaging.ImageFormat.Jpeg)
                End If
    
            End If
        Catch ex As Exception
            CreateLogTextFile(String.Format("Error on Capture Image Request >> {0}", ex.Message.ToString), False)
        End Try
        Return IO.Path.Combine(imagePath, fileName)
    End Function
    

    我需要你的帮助。非常感谢。

    1 回复  |  直到 7 年前
        1
  •  1
  •   preciousbetine    7 年前

    试试这个

     Dim bm As Image = Image.FromStream (stream)
     bm.Save(file, Imaging.ImageFormat.Jpeg)
     bm.Dispose ()