我正在尝试通过套接字从服务器向客户端发送图像。我将位图图像转换为字节数组并将数组发送到客户端。但是现在我遇到了将数组字节转换回客户端位图的问题。现在我的位图print语句告诉我,我的位图值是" null"。有谁知道如何解决这个问题所以我可以将我的位图图像保存为客户端的png?
我的客户端代码,它以数组中的字节接收图像
try {
System.out.println("TRY");
Socket socket = new Socket("192.168.0.26", 5050);
// Get data sent through socket
DataInputStream DIS = new DataInputStream(socket.getInputStream());
System.out.println("DataInputStream Started");
// read data that got sent
String msg_received = DIS.readUTF();
System.out.println("Message from server" + msg_received);
String PACKAGENAME = DIS.readUTF();
System.out.println("Message from server" + PACKAGENAME);
// read array data for bitmap
byte[] data;//String read = input.readLine();
int len= DIS.readInt();
data = new byte[len];
if (len > 0) {
DIS.readFully(data,0,data.length);
}
bitmap = BitmapFactory.decodeByteArray(data , 0, data.length);
socket.close();
} catch (Exception e) {
System.out.println("Did not receive string");
}