Saranjith
Saranjith

Reputation: 11577

How to locate image from a Bytes Android

Currently i have byte array. Which contains a .jpg file also some other unwanted data.

What I wanted to do is to find out the position of data "FF D8" (start of JPEG data).

Same Code in iOS is : https://stackoverflow.com/a/18477915/5215474

Upvotes: 0

Views: 72

Answers (1)

Stephen C
Stephen C

Reputation: 719346

This is trivial to implement in Java.

int position = -1;

for (int i = 0; i < bytes.length - 2; i++) {
    if (bytes[i] == (byte) 0xff && bytes[i + 1] == (byte) 0xdf) {
        position = i;
        break;
    }
}

Upvotes: 3

Related Questions