1

I currently have a VirtualDisplay set up using the MediaProjection API which is being drawn on to a SurfaceView that is always visible. The VirtualDisplay is, however, capturing the entire display but I would like it do capture only the portion of which the SurfaceView is covering. Is there any solution to this, I would appreciate the help?

enter image description here

Noam Suissa
  • 428
  • 4
  • 23
  • Can't you [set the screen size](https://learn.microsoft.com/en-us/dotnet/api/android.media.projection.mediaprojection.createvirtualdisplay?view=xamarin-android-sdk-12) when creating the VirtualDisplay? – Eugenio Jan 12 '22 at 17:23
  • That just sets the size of the VirtualDisplay, which still contains the entire screen. – Noam Suissa Jan 12 '22 at 17:25
  • I've read around and it seems impossible to do with this API, try reading [here](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API), if it's not out of date it should do the trick. – Eugenio Jan 12 '22 at 17:38
  • I am using Java, please refer to the appropriate documentation. – Noam Suissa Jan 12 '22 at 18:00
  • Sorry, I didn't realise, try [this](https://www.geeksforgeeks.org/how-to-capture-screenshot-of-a-view-and-save-it-to-gallery-in-android/) guide, from the mini introductory video it looks like it only screens the logo, so not full screen. – Eugenio Jan 12 '22 at 21:27
  • if you want to record surface,you can use recordablesurfaceview https://github.com/spaceLenny/recordablesurfaceview – EAS Jan 13 '22 at 09:39
  • Thank you for that but I do not need to save a recording to a file, I simply want to achieve what is shown in the image. @Eugenio this does not really help because he is simply saving the image that is being held in the View. – Noam Suissa Jan 13 '22 at 14:12

1 Answers1

0

Thanks to this question, I have found a solution. Setting the SurfaceView's scale was the key:

mSurface.setScaleX(/*scale factor*/);
mSurface.setScaleY(/*scale factor*/);

As for the scale factors, I am currently trying with trial and error until I get a perfect fit and it blends in perfectly with the background, but I will try to do it in a more programmatic and precise manner.

Noam Suissa
  • 428
  • 4
  • 23