I am using Android ImageReader class to receive Bitmaps from MediaProjection.createVirtualDisplay method.
My code so far looks like this:
mProjectio
Fo those of you looking for the easiest way to capture from ImageReader to a JPG (be it bytes on disk or in memory) It's actually quite simple.
Given an ImageReader, set it to ImageFormat.JPEG:
ImageReader imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), imageFormat, 1);
Then in the CameraCaptureSession.StateCallback:
captureSession.capture(captureRequest, new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
Image image = imageReader.acquireLatestImage();
final Image.Plane[] planes = image.getPlanes();
final ByteBuffer buffer = planes[0].getBuffer();
buffer.rewind();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
}
}
Then you have bytes which you can do anything with. Send them over a socket, to a file, hash them, etc.