mtsahakis / MediaProjectionDemo

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

Bug: black margins on left and right #10

Open AndroidDeveloperLB opened 7 years ago

AndroidDeveloperLB commented 7 years ago

Just noticed that the sample produces files with black left&right margins:

myscreen_5

Why does it occur? What should be done to fix it? Tested on Nexus 5x with Android 7.1.2

mtsahakis commented 7 years ago

Please check http://stackoverflow.com/questions/27581750/android-capture-screen-to-surface-of-imagereader for a full explanation.

If you try adding the solution, this is the patch:

diff.txt

I am not going to apply it in the demo as it is a performance killer (check the two loops it performs) but for a use case you mentioned in another thread (capturing a single image, I think you added a new task for that) should be fine.

mtsahakis commented 7 years ago

Basically Image.Plane buffers have some padding for each row that you either accept it in the final product and add it to the bitmap (black margins) or you try to remove it (but removal is slow).

AndroidDeveloperLB commented 7 years ago

But it adds this padding not just in the end, but also in the beginning. The link you've provided says it's only at the end, and it's also the solution there: https://commonsware.com/Android/previews/screenshots-and-screen-recordings

AndroidDeveloperLB commented 7 years ago

Anyway, I've put a StackOverflow question about this:

http://stackoverflow.com/q/43705756/878126