Screenshotter
Screenshotter copied to clipboard
Getting Exception ava.lang.UnsupportedOperationException: The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4.
Process: com.jni.screenshotter, PID: 1511 java.lang.UnsupportedOperationException: The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4. at android.media.ImageReader.nativeImageSetup(Native Method) at android.media.ImageReader.acquireNextSurfaceImage(ImageReader.java:298) at android.media.ImageReader.acquireNextImage(ImageReader.java:344) at android.media.ImageReader.acquireLatestImage(ImageReader.java:248) at in.omerjerk.libscreenshotter.Screenshotter.onImageAvailable(Screenshotter.java:107) at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:548) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
On what device are you facing this issue if I may know? :)
I have the same Issue on a Samsung S4 mini GT-I9195, Android Version 6.0.1.
I also have the same crash on my Nexus 5x. If I use ARGB_8888 it doesn'T crash, but i get a black image. Would be nice if you could figure out what's wrong. I was investigating the last two days to get an image (bitmap) out of the current screen...
I changed as follows: //mImageReader = ImageReader.newInstance(width, height, ImageFormat.RGB_565, 2); mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);
Seems to work
@moster67 I also tried this one, but just got a black image on my Nexus 5x. Do you get a correct image?
I'm really sorry. I realise that this issue is bugging a lot people. In my opinion, the only solution is to avoid the ImageReader API altogether and use OpenGL APIs. The only thing blocking me to implement it is just that it's too much of work and I don't have much motivation for that. :(
@Fishfield I tried on Nexus4 but I will this evening try on some other devices and then report back.
@omerjerk No worries. I still appreciate your work and that you shared it with us.
I searched around in the interenet a lot the last months and the solution with the ImageReader API was the most found answer. I am just curious why it worked for them although the solution was exactly the same as mine. @omerjerk did it ever work for you?
@omerjerk I am curious about how you implemented it in your screenshot application on the play store?
Hi, When i try to screenshot a video on Youtube for example, i get a black bitmap in RGB format and if i change the format in ImageReader.newInstance to YUV i has the same error message. Have you an idea ?
Hi @Raphdeumax
If you are getting a black image while screenshotting youtube app, it might be possible that youtube has made it's display secure. You can read about secure display here - https://developer.android.com/reference/android/view/Display.html#FLAG_SECURE
@omerjerk, Thanks for your repsonse, i will investigate on the secure flag. I has appreciate your work ;-)
For information, i has the same problem using OpenGL.
Hello, After testing, the FLAG_SECURE has no link to the black screen when capturing video. Small question, what is the role of the mediaencoder when using MediaProjection?
thank you
mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2)
worked on my Samsung phone, but no save to media folder as of yet
The producer output buffer format is 0x1 in some android emulator,and is 0x2 in some android emulator, I don't get the compatible idea
I think what can we do is catch the exception and get the producer output format info, then recreate the ImageReader in the format