我使用蓝牙将图像从Android camera.callback传输到PC。在Windows端我使用DataInputStream来读取传入的数据。问题是PC端无法检测到第一张图像和第二张图像的结束。因此我无法重建图像。
DataoutputStream的错误在以下代码中
public void create_file() {
synchronized (frames) {
if (frames.size() > 0) {
Log.i("dhiraj", "" + frames.size());
YuvImage image = new YuvImage(frames.remove(0),
ImageFormat.NV21, size.width, size.height, null);
try {
out = new DataOutputStream(client.getOutputStream());
} catch (IOException e1) {
Log.i("dhiraj", "new outstream error");
e1.printStackTrace();
}
Log.i("dhiraj", "new outstream");
image.compressToJpeg(rectangle, 90, baos);
Log.i("dhiraj", "compressed");
try {
out.write(baos.toByteArray());
Log.i("dhiraj", "" + baos.size());
Log.i("dhiraj", "output");
} catch (IOException e) {
Log.i("dhiraj", "IO");
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
Log.i("dhiraj", "new outstream close error");
e.printStackTrace();
}
}
}
}
答案 0 :(得分:0)
是否可以在每张图片之前发送尺寸?所以你可以读取n个字节。 也许将大小写入文件。
伪:
for (each image)
write (size of image) to size.txt on Android
transfer size.txt to PC
read the (size of image) from size.txt
read for (size of image) from bluetooth
end for
另一种选择是在每张图像的末尾添加一个非常独特的字符序列,并在接收后将其删除。 如果这不够独特,你就有可能在图像的某个地方找到那个序列并将图像分成碎片。