我正在尝试让android通过tcp / ip将图像发送到vb.net服务器。 Android会压缩位图,当服务器收到位图并将其转换为图像时,它会变成黑色我认为解压缩可能是问题或其他问题。我真的不知道如何解压缩该图像。任何帮助,将不胜感激。感谢。
这是创建位图的Java:
Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byteArray = stream.toByteArray();
这是我的vb.net服务器
Sub Main()
Dim bmp As Bitmap
Dim serverSocket As New TcpListener(1334)
Dim requestCount As Integer
Dim clientSocket As TcpClient
serverSocket.Start()
While (True)
Try
msg("Waiting For Client...")
clientSocket = serverSocket.AcceptTcpClient()
msg("Accept connection from client")
requestCount = requestCount + 1
Dim networkStream As NetworkStream = clientSocket.GetStream()
Dim bytesFrom(clientSocket.ReceiveBufferSize) As Byte
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
Dim newImage As Image = Nothing
Byte2Image(newImage, bytesFrom)
newImage.Save("C:\Users\ppetrenko\Desktop\test.jpeg")
Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
msg("Data from client - " + dataFromClient)
Dim serverResponse As String = "Server response " + Convert.ToString(requestCount)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(serverResponse)
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Flush()
msg(serverResponse)
clientSocket.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End While