While using the analyze() function in ImageAnalysis.Analyzer class to retrieve a picture and operate on it (do something with it), I am encountering different behavior on different Android devices. The same code, when run on a solid Samsung device returns a regular picture that I can use. But when run on a lower-end android device, it does not.
The analyze code:
private class NAnalyzer implements ImageAnalysis.Analyzer {
@Override
public void analyze(@NonNull ImageProxy image) {
time = System.nanoTime();
ImageProxy.PlaneProxy[] planes = image.getPlanes();
ByteBuffer yBuffer = planes[0].getBuffer(); //Y
ByteBuffer uBuffer = planes[1].getBuffer(); //U
ByteBuffer vBuffer = planes[2].getBuffer(); //V
int ySize = yBuffer.remaining();
int uSize = uBuffer.remaining();
int vSize = vBuffer.remaining();
byte[] nv21 = new byte[(ySize + uSize + vSize)];
yBuffer.get(nv21, 0, ySize);
vBuffer.get(nv21, ySize, vSize);
uBuffer.get(nv21, ySize + vSize, uSize);
YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, image.getWidth(), image.getHeight(), null);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yuvImage.compressToJpeg(new Rect(0,0, yuvImage.getWidth(), yuvImage.getHeight()), 100, stream);
byte[] imageBytes = stream.toByteArray();
//raw = data container
raw = imageBytes;
//nRunnable - operates the picture
nRunnable.run();
image.close();
}
}
The low-end picture can be found here
I assume that this is a hardware issue, but if anyone knows otherwise I would appreciate the help.