Нарисуйте прямоугольник автофокуса в предварительном просмотре с помощью camera2 android

Я использую Camera2 API Android. Я могу захватить изображение и сохранить его. Я использую режим autofocus для фокусировки и захвата изображений.

captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

где есть CaptureBuilder

private CaptureRequest.Builder captureBuilder;

Я хочу показать прямоугольник или круг в области автофокуса в предварительном просмотре камеры, как это происходит в приложении камеры по умолчанию. Например, прямоугольник в середине предварительного просмотра здесь.

введите здесь описание изображения

Я видел это, но я не хочу ничего трогать где-либо в предварительный просмотр.

Я просмотрел множество примеров, но большинство из них иллюстрируют использование устаревшего класса Camera, ничего полезного в Camera2 API. Как этот прямоугольник фокусировки может быть достигнут с помощью нового API камеры?


person Kamalpreet Grewal    schedule 05.11.2016    source источник
comment
проверьте ответ в этой теме: stackoverflow.com/questions/31173476/.   -  person user1035292    schedule 28.02.2017


Ответы (1)


Похоже, вам просто нужен статический прямоугольник в центре предварительного просмотра.

Вы можете сделать это с помощью макета xml, добавив изображение в макет.

Возьмем пример Camera2Basic (https://github.com/googlesamples/android-Camera2Basic) и добавив его к этому, пример ниже добавляет прямоугольник, некоторый текст и кнопки управления сбоку (это для альбомной ориентации):

<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>
person Mick    schedule 10.04.2017
comment
после добавления этого прямоугольника через XML, как я могу получить только изображение этой прямоугольной части? не полное изображение - person Riddhi Shah; 19.06.2019