Parameter is not valid." RRS feed

  • Question

  • User564383478 posted

    Dear friends advance thanks
    i am troubling with my problem from the last few weeks.Pls check the step what i did.

    image data is sending by a vehicle tracking unit.using a socket application i am tracing that data.the data from the vehicle tracking unit is not in a decimal format.image data coming from socket containing lot of special type of characters. so i am converting this image information to hex format using the code below.

    Private Function Data_Asc_Hex(ByRef Data As String) As String
    On Error Resume Next
    'first take each charcter using substring.
    'then convert character into ascii.
    'then convert ascii value into Hex Format
    Dim sValue As String
    Dim sHex As String = ""

    While (Data.Length > 0)
    sValue = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString))
    Data = Data.Substring(1, (Data.Length - 1))
    sHex = (sHex + sValue)
    End While
    Return sHex

    End Function

    i am calling the function like as follows

    Dim Image As String = ""
    ''convert image details to hex
    If TestArray(3) <> "" Then 'convert to hex
    Image = Data_Asc_Hex(TestArray(3))

    End If

    after converting image data to hex format,i did the steps what i specified below.
    for eg:after step 1 i got image data in socket application in hex format like as follows



    '--hex to byte
    Dim hex As String = "D0043D23FA4682EFAB507FFD6E74BD34BD234185EA367A03FFFD7E33F3FF125223F1253BCCA67FFFD0E53CCA3CCA453F3F473F401FFFD1E57CCA43F3F1DE65064A0FFFD2E4CCBEF4D32D22C619698D28A047FFD3E03FC4533FF43F385C52FDA05033FFD4E23CFA3ED029141F68A3ED23F3FFFD5E23ED028FB40A450A2E47AD0D7231D683FFD6E03FE73F69B9343F30DC1A693FD33FFD7F38F30D2F93F3FDE63F71A067FFD0F3BF30D1BDA8183F8FAD193EB41FFD1F3AC3F32681864D13F401FFFD2F33F314093F4C507FFD9D"
    Dim NumberChars As Integer = Hex.Length
    Dim bytes As Byte() = New Byte(NumberChars / 2 - 1) {}
    For i As Integer = 0 To NumberChars - 1 Step 2
    bytes(i / 2) = Convert.ToByte(Hex.Substring(i, 2), 16)


    'bytearray to base 64
    If bytes Is Nothing Then Throw New ArgumentNullException("bytes")
    Dim str64 As String = Convert.ToBase64String(bytes)

    STEP 5
    Dim img As System.Drawing.Image
    Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream

    Dim b64 As String = str64
    Dim b() As Byte

    'Converts the base64 encoded msg to image data
    b = Convert.FromBase64String(b64)
    MS = New System.IO.MemoryStream(b)

    'creates image
    img = System.Drawing.Image.FromStream(MS)

    'writes image for displaying
    img.Save("c:\pict1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    'cleaning up house

    STEP 6
    getting an error
    "Parameter is not valid." in the line

    img = System.Drawing.Image.FromStream(MS)

    can anybdy help me to findout where the problem is?

    Wednesday, August 18, 2010 12:27 AM


  • User604186779 posted

    getting an error
    "Parameter is not valid." in the line

    img = System.Drawing.Image.FromStream(MS)

    This may help you


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 18, 2010 4:18 AM