Android 检测通过蓝牙传输的两个图像之间的EOF

Android 检测通过蓝牙传输的两个图像之间的EOF,android,bluetooth,camera,Android,Bluetooth,Camera,我使用蓝牙将图像从Android camera.callback传输到PC。在windows端,我使用DataInputStream读取传入数据。问题是PC侧无法检测第一图像和第二图像的结束。因此,我无法重建图像 DataoutputStream的错误在以下代码中 public void create_file() { synchronized (frames) { if (frames.size() > 0) { Log.i("dh

我使用蓝牙将图像从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();
            }
        }
    }
}

是否可以在每张图片之前发送尺寸?因此,您可以只读取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
另一种选择是在每个图像的末尾附加一个非常独特的字符序列,并在接收后将其去除。
如果这不够独特,您可能会在图像中的某个位置找到该序列并将图像切碎。

我可能会这样做,但这会大大降低整个操作的速度。我想发送的图像非常快,以便他们可以被投影,我们得到的看法,就像一个视频播放。。。否则我想用Bluetooth将摄像头预览流式传输到pc,这会大大降低整个操作的速度??正在发送包含几个字符的文件。。。或者更好的是只是一个作为ByTestStream的整数。。。只有几个字节。实际上只有两种选择:1、终止字符或序列。2附上一个页眉,页眉的大小要知道要读多少。您可以将大小作为单独的xfer发送,而不是向图像添加标题,以简化操作。您是否检查过正在发送的图像格式是否没有终止序列/字符?在十六进制编辑器中打开一些图像,看看是否可以识别出它们在结尾处的共同模式。是的,它们都以FF D9作为终止字符…:还是不走运!当我在android端关闭DataOutputStream时,图像被正确地重建,所以我尝试在每次写入后关闭它,并在循环中再次创建它,但它给了我错误。Logcat读取java.lang.RuntimeException:发布后调用的方法