Android: Fix java.lang.ArrayIndexOutOfBoundsException with image rotation

This commit is contained in:
Ville Ahti
2018-05-17 14:33:49 +03:00
parent a4599093ea
commit 6ce014d3ca
@@ -108,7 +108,11 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
byte[] rotated = new byte[imageData.length];
for (int y = 0; y < width; y++) {
for (int x = 0; x < height; x++) {
rotated[x * width + width - y - 1] = imageData[x + y * height];
int sourceIx = x + y * height;
int destIx = x * width + width - y - 1;
if (sourceIx >= 0 && sourceIx < imageData.length && destIx >= 0 && destIx < imageData.length) {
rotated[destIx] = imageData[sourceIx];
}
}
}
return rotated;