mtsahakis / MediaProjectionDemo

One Activity sample app of using Android Lollipop MediaProjection API to capture device screenshots
Other
211 stars 76 forks source link

Screenshots get all blured and fuzzy when testing on a Nexus 5 #3

Closed RazorPT closed 9 years ago

RazorPT commented 9 years ago

Funny thing the app works correctly on the emulator but not on a Nexus 5 device: myscreen_0 1

mtsahakis commented 9 years ago

I have tested the app on emulator and on a Nexus 7 with 5.0.2 and worked fine. Which Android version is your Nexus 5 running? Also, I recently changed ImageFormat from ImageFormat.JPEG to ImageFormat.RGBA_8888, try the other way round and let me know if it had any effect.

mtsahakis commented 9 years ago

Have a look also at http://stackoverflow.com/questions/26673127/android-imagereader-acquirelatestimage-returns-invalid-jpg/28843224#28843224 especially an answer provided by binW.

RazorPT commented 9 years ago

My nexus 5 is running 5.0.1 i tested changing PixelFormat.RGBA_8888 to .JPEG but it started giving me this error on logcat "[unnamed-31494-2] dequeueBuffer: can't dequeue multiple buffers without setting the buffer count and didn´t produce any screenshots", reverting to original code to PixelFormat.RGBA_8888 starts producing screenshots with the old problem.

It is really weird problem, it will take a look into that stackoverflow answer

RazorPT commented 9 years ago

Okay i just tested the code from the stackoverflow answer and replaced your code:

Image.Plane[] planes = image.getPlanes(); Buffer imageBuffer = planes[0].getBuffer().rewind();

// create bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(imageBuffer);

With the code from the stackoverflow answer and problem solved! At least for me :) It seems the problem is that you can´t generate a bitmap with the same size as the virtual display since the returned images are bigger so you have to take into account the PixelStride and RowStride. You can read more on the author´s blog: http://binwaheed.blogspot.com

I can´t seem to reproduce your problem with "The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4"

By the way any idea to how to screen capture as a video? (Screen record)

mtsahakis commented 9 years ago

I got the Exception on my Nexus 7 so perhaps I missed some step along the way. Can you send me the exact diff so as to have a look?

Regarding video I don't see how you can do it with this API, in case you find any solution though let us know :)

mtsahakis commented 9 years ago

Had time today so made more tests on this.

My observations, based on a Nexus 7 running Android 5.0.2:

  1. When I use the stackoverflow answer i.e. mImageReader = ImageReader.newInstance(mWidth, mHeight, ImageFormat.RGB_565, 2); and bitmap = Bitmap.createBitmap(mWidth+rowPadding/pixelStride, mHeight, Bitmap.Config.RGB_565); I get E/ImageReader_JNI(20606): Producer output buffer format: 0x1, ImageReader configured format: 0x4
  2. When I use the stackoverflow answer with mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2); and bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.RGB_565); I get blurred images (makes sense).
  3. When I use the stackoverflow answer with mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2); and bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888); all works fine. I the almost the same images I get with the my latest commit (4877e0c86be25532b7da9bcb84e23df224967012).

I will update the code to reflect the change.

VINNUSAURUS commented 5 years ago

Unable to get PixelFormat enum in xamarin android? any idea?