阅读二进制图像
我有我的套接字通信启动和运行。阅读二进制图像
我现在需要用以下帮助:
我们正在经历插座的图像发送到设备。
transmit.framebuffer.rgb_byte will transmit in binary format the following information:
[4 bytes] => image width
[4 bytes] => image height
[< image width> * <image height> * 3 bytes] => RGB in unsigned char format [0, 255]
[3 bytes] "OK\n"
我将如何去获得这个工作?.. 现在我只是纯文本等工作, 所以这整个二进制编码是新的我。
这是一个例子可以读取客户端上的数据:
out = new ByteArrayOutputStream();
in = new BufferedInputStream(socket.getInputStream(), BUFFER_SIZE);
byte[] dataBuffer = new byte[1024 * 16];
int size = 0;
while ((size = in.read(dataBuffer)) != -1) {
out.write(dataBuffer, 0, size);
}
out.flush();
byte[] bytesReceived = out.toByteArray();
谢谢。只需要让我的头缠住这个。 如何继续将抓取的数据插入到picturebox? – 2011-05-10 19:26:27
我需要说的是,听起来很奇怪。为什么服务器不是以有效的图像格式发送图像?例如。一个PNG或JPG。这将是更容易显示图像。 – Kaj 2011-05-10 19:33:08
看起来你可以将byte []转换为一个整数数组(而你需要将OR转换为一个整数),然后使用http://developer.android.com/reference/android/graphics/Bitmap .html#createBitmap(int [],int,int,android.graphics.Bitmap.Config) – Kaj 2011-05-10 19:49:57
有什么问题吗?使用(Buffered)InputStream /(Buffered)OutputStream,并写入字节。 – Kaj 2011-05-10 19:10:40