I have an image that is stored as a byte [] array, and I want to flip the image vertically before writing bytes to another disk.
Image bytes come from a compressed jp2 image file. I was looking for an implementation of something like a Flip image stored as a byte [] array , but I do not work in android and do not have access to BitmapFactory. I also looked at converting a byte array to a BufferedImage, and then flipped it over, but the height and width of the image are unknown in the current context (EDIT: I changed the code so that the height and width are now known).
Is there a way to do this only with strict array manipulation?
EDIT: Attempting a 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; }
source share