Search code examples
javaandroidarraysjpegmjpeg

jpeg bytes to hex value


I'm receiving a stream via uvc, which gives me each mjpeg stream.

When writing the jpeg frame into a bitmap, the byte array viewed from the debugger looks like this :

{ 0, -128, 1, -128, 0, -128, .......}

I create the file by doing this:

bitmap.copyPixelsFromBuffer(frame);
File file = new File(Constants.CAPTURE_PATH, System.currentTimeMillis() + ".jpeg");
file.createNewFile();
out = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

After I create the file and look inside it with a hex viewer, the file looks like this :

FF D8 FF E0 00.....

Does this mean that {0} became FF, and {-128} became D8?

What rules made this happen? Any help will be very thankful.


Solution

  • It's possible that you are looking at the JPEG file header if these are the very first bytes in the file as seen by the file hex viewer. FF D8 FF look strikingly similar. See here for example and wikipedia page here.

    I'd expect that data you are looking at in the debugger is the raw image data which won't include the header.