System.FormatException在ConvertFromBase64String上

时间:2014-03-23 12:25:49

标签: vb.net base64 autoit

这是一个提问的好地方! 我遇到了一个问题。

我试图将图像从AutoIT客户端发送到用VB.NET编写的服务器 以下是AutoIT客户端的代码:

    TCPStartup()
$MainSocket = TCPConnect("127.0.0.1", 9832)


$PATH = _ScreenCapture_Capture("")
$Data2Send = "RemoteDESK|" & _Base64Encode(HBITMAP_To_Bytes($PATH)) & "<EOF>"
TCPSend($MainSocket, $Data2Send)

这是VB.NET服务器的代码: 数据处理程序:

Private Sub GotInfo(ByVal Data As String, ByVal Sender As Socket)
        Dim Cut() As String = Data.Split("|")
        Select Case Cut(0)
            Case "RemoteDESK"
                Dim ImgString As String = Cut(1)
                PictureBox1.Image = B64ToImage(ImgString) 
        End Select
    End Sub

基本64字符串到图像功能:

Private Function B64ToImage(ByVal B64 As String) As Image
        Dim ByAr() As Byte = Convert.FromBase64String(B64) 'Exception Happens here
        Dim img As Image
        Dim MS As New MemoryStream(ByAr)

        Try
            img = Image.FromStream(MS)
        Catch ex As Exception
            Return Nothing
        End Try

        Return img
    End Function

OnReceive Sub:

 Private Sub OnReceive(ByVal ar As IAsyncResult)
        Dim Content As String = String.Empty
        Dim State As StateObject = DirectCast(ar.AsyncState, StateObject)
        Dim Handler As Socket = State._MySocket
        Try
            Dim BytesRead As Integer = Handler.EndReceive(ar)
            If BytesRead > 0 Then
                State._SB.Append(Encoding.ASCII.GetString(State.Data))
                Content = State._SB.ToString
                If Content.IndexOf("<EOF>") > -1 Then
                    Dim ReadContent As String = Content.Remove(Content.IndexOf("<EOF>"))
                    RaiseEvent GotInfo(ReadContent, State._MySocket)
                Else
                    Handler.BeginReceive(State.Data, 0, State.BufferSize, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), State)
                End If
            End If
        Catch ex As Exception
            RaiseEvent ClientDC(Handler)
        End Try

    End Sub

1 个答案:

答案 0 :(得分:0)

好吧,现在我使用了文本比较工具,每次在第53行,接收到的字符串都发生了变化,因为2行文本与自动输出相比在同一行。 自动输出是可读的。