I am trying to take screenshots of my Android device (Samsung Galaxy Tab S5e) using a service. I am using the code from here.
In the code linked, ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
is used. Note the PixelFormat.RGBA_8888
. Now, this won't allow me to compile my project and I am greeted with the error: Error: Must be one of: ImageFormat.UNKNOWN, ImageFormat.RGB_565... etc
.
So I tried changing PixelFormat.RGBA_8888
to ImageFormat.JPEG
and it compiles. However, my app now crashes with the message:
RGBA override BLOB format buffer should have height == width
I've tried changing PixelFormat.RGBA_8888
to 0x4
, 0x1
, ImageFormat.RGB_565
and a few others. Doing so often results in an exception with the message:
The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4.
This is somehow linked with the format described in onImageAvailable(ImageReader reader)
.
I've seen the following SO post, and it seems the correct format is device-specific, but I've tried them all and the error is one of the above.
I'm at a total loss (and I'm a Java/Android newb), so could really use some help.