I have an image which is stored as a byte[] array, and I want to flip the image vertically before writing the bytes to disk elsewhere.
The image bytes come from a compressed jp2 image file. I've looked into implementing something like Flip image stored as a byte[] array, but I'm not working in android and don't have access to BitmapFactory. I've also looked into converting the byte array to a BufferedImage first, then flipping it, but the height and width of the image isn't known in the current context (EDIT: I've modified the code so the height and width are now known).
Is there a way to do this just with strict array manipulation?
EDIT: Attempted flip code
public static byte[] flip(byte[] imageBytes) {
//separate out the sub arrays
byte[] holder = new byte[imageBytes.length];
byte[] subArray = new byte[dimWidth];//dimWidth is the image width, or number of matrix columns
int subCount = 0;
for (int i = 0; i < imageBytes.length; i++) {
subArray[subCount] = imageBytes[i];
subCount++;
if (i% dimWidth == 0) {
subArray = reverse(subArray);
if (i == (dimWidth)) {
holder = subArray;
} else {
holder = concat(holder, subArray);
}
subCount = 0;
subArray = new byte[dimWidth];
}
}
subArray = new byte[dimWidth];
System.arraycopy(imageBytes, imageBytes.length - dimWidth, subArray, 0, subArray.length);
holder = concat(holder, subArray);
imageBytes = holder;
return imageBytes;
}