androidpreviewgrafika

How to make the area of camera preview be half of SurfaceView in ContinuousCaptureActivity


I want to make the area of camera preview be half of SurfaceView, so I modify the code of ContinuousCaptureActivity. The detail is as follows:

Use GLES20.glViewport(0, 0, viewWidth / 2, viewHeight / 2); to replace https://github.com/google/grafika/blob/master/src/com/android/grafika/ContinuousCaptureActivity.java#L436

But the result is strange, see the picture below.

enter image description here

I really can not understand it and what is the right way to do it?

Who can give me some advices?


Solution

  • My first thought would be that you need a glClear() in there (with the viewport set to cover the entire surface) since you're no longer filling the entire surface with the blit. Otherwise you get uninitialized data, and on a tile-based architecture things can get strange.

    Fiddling with the viewport isn't really the right way to go. Just draw a smaller rectangle. Use Sprite2d and change the X/Y scale factors. See TextureFromCameraActivity for an example -- you can scale the rect, zoom in, rotate, etc.