Android: Overlay on Android Camera Preview

后端 未结 6 582
后悔当初
后悔当初 2020-11-27 13:32

I\'m using Camera API and invoking the camera.

I want to display a header (for branding) on the top of the camera preview. The header is a jpeg image.

Is

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 14:10

    A workaround alternative is to overlay the Activity XML file with another XML file which contains the header image. To do so:

    1. Create a new Layout file inside the layout folder. For eg: overlay.xml
    2. Insert an ImageView inside it, something like:

      
      
      
      
      
      
      
    3. Then inside the Activity java file, ie MotionDetector.java file , create a new method addView() :

         private void addView()
         {
             controlInflater = LayoutInflater.from(getBaseContext());
             View viewControl = controlInflater.inflate(R.layout.overlay, null);
             LayoutParams layoutParamsControl = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
             this.addContentView(viewControl, layoutParamsControl);
      
         }
      
    4. Finally invoke the addView() method from onCreate() to add the image:

      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.header);
      addView();
      

    Then end result would be an image overlay above the SurfaceView. Subject to the quality of the header image, the rendered quality of the header shall seem original. Hope it helps.

提交回复
热议问题