Im using Bluetooth to transfer image from Android camera.callback to PC. on windows side i use DataInputStream to read the incoming data. the problem is that the PC side cannot detect the end of first image and second image. hence i cannot reconstruct the image.
the error of DataoutputStream is in following code
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();
}
}
}
}
Would it be possible to send the size before each image? So you can just read for n bytes.
Perhaps write the size to a file.
Pseudo:
Another option is to append a very unique sequence of characters to the end of each image, and strip it off after reception.
If this isn’t unique enough you run the chance of finding that sequence somewhere in the image and chopping an image in pieces.