Draw autofocus rectangle in preview using camera2 android -


i using camera2 api of android. able capture image , save it. using autofocus mode focus , capture images.

capturebuilder.set(capturerequest.control_af_mode, capturerequest.control_af_mode_continuous_picture); 

where capturebuilder is

private capturerequest.builder capturebuilder; 

i want show rectangle or circle in autofocus area in camera preview happens in default camera application. instance rectangle in middle of preview here.

enter image description here

i have seen this not want on touching anywhere in preview.

i have searched through lot of examples of them illustrate use of deprecated camera class, nothing useful on camera2 api. how can focus rectangle can achieved new camera api?

it looks want static rectangle in center of preview.

you can via xml layout adding image layout.

taking camera2basic example (https://github.com/googlesamples/android-camera2basic) , adding this, example below adds rectangle, text , control buttons on side (it landscape orientation):

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <com.example.android.camera2basic.autofittextureview         android:id="@+id/texture"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentstart="true"         android:layout_alignparenttop="true" />      <linearlayout         android:id="@+id/control"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true"         android:layout_alignparenttop="true"         android:background="@color/colorprimary"         android:orientation="vertical">          <space             android:layout_width="1dp"             android:layout_height="0dp"             android:layout_weight="1" >         </space>          <textview             android:id="@+id/label1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:text="@string/label1_text" />          <space             android:layout_width="1dp"             android:layout_height="0dp"             android:layout_weight="1" >         </space>          <button             android:id="@+id/picture_button"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:text="@string/picture_button_text" />          <space             android:layout_width="1dp"             android:layout_height="0dp"             android:layout_weight="1" >         </space>          <imagebutton             android:id="@+id/info"             style="@android:style/widget.material.light.button.borderless"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal|bottom"             android:contentdescription="@string/description_info"             android:padding="20dp"             android:src="@drawable/ic_action_info" />          <space             android:layout_width="1dp"             android:layout_height="0dp"             android:layout_weight="1" >         </space>      </linearlayout>      <relativelayout         android:id="@+id/tileview"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_toleftof="@+id/control"         android:background="@android:color/transparent" >          <imageview             android:id="@+id/autofocus_rectangle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:src="@drawable/autofocus_landscape_image"             android:layout_centerinparent="true" />          <textview             android:id="@+id/bottom_text"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:layout_alignparentbottom="true"             android:layout_margin="10sp"             android:background="@android:color/holo_blue_dark"             android:textsize="15sp"             android:padding="5sp"             android:text="" />      </relativelayout>  </relativelayout> 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -