How to set background to the outer portion of frame in android using surfaceview

浪子不回头ぞ 提交于 2019-12-08 11:56:10

问题


Hello guys,

My problem is how can I fill the outer portion of the frame. I need to show the camera moments inside the frame only. The rest of the portion will filled up with the color what we choose to fill.

Here this is the whole background captured from the camera but I don't want this.

Please suggest me what I should do?

Your true guidance and support will be additional and your efforts will highly be appreciated once you're sure to done with this.


回答1:


You have two options if you don't want the camera preview to fill the entire area covered by the SurfaceView:

  1. Draw something on top of the SurfaceView.
  2. Use OpenGL ES to render the camera preview in whatever shape you want.

Option #1 is pretty straightforward. The SurfaceView surface is composited below the View UI layer, so anything you draw in a View will appear on top (e.g. the blue circle in the image you included). Just draw opaque pixels everywhere you don't want the camera preview to appear. You should be able to use the SurfaceView's View by specifying a custom onDraw().

Option #2 is more involved, but does give you more flexibility in how you display the camera image. The "texture from camera" activity in Grafika demonstrates this.



来源:https://stackoverflow.com/questions/26655236/how-to-set-background-to-the-outer-portion-of-frame-in-android-using-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!