0

I am developing an app that is using face recognition. I have managed to draw an image over the camera, but the image is not transparent.

face image

I want the face to be transparent like we have in a real camera. i have tried to follow this post: Change background color to a limited area of a view - Android

what is the best way to achieve this ?

This is my layout:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:background="@android:color/black"
    android:orientation="vertical">

    <com.facekeyexample.views.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <TextView
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLines="1"
        android:padding="12dp"
        android:text="@string/align_face"
        android:textColor="@android:color/white"
        android:textSize="16dp"
        android:textStyle="bold" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/message"
        android:alpha="0.77"
        android:background="@color/transparent_darkIndigo"
        android:orientation="vertical">

        <TextView
            android:id="@+id/counter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginBottom="32dp"
            android:padding="5dp"
            android:text="3"
            android:textColor="@android:color/holo_orange_light"
            android:textSize="120dp"
            android:textStyle="bold"
            android:visibility="gone" />

        <View
            android:id="@+id/elipseShape"
            android:layout_width="320dp"
            android:layout_height="430dp"
            android:layout_centerInParent="true"
            android:background="@drawable/face"
            />


        <com.facekey.liveness.LivenessView
            android:id="@+id/livenessView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="gone" />
    </RelativeLayout>
</RelativeLayout>

Thank you

Maxim Toyberman
  • 1,906
  • 1
  • 20
  • 35
  • I think you'd need to simply crop your path and set it as alpha0 (transparent) in the image below. [This](https://stackoverflow.com/questions/11932805/cropping-circular-area-from-bitmap-in-android) is not the exact example, but should be similar to what I'd try first. – Martin Marconcini Jul 02 '19 at 13:13
  • @MartinMarconcini I have succeeded to do it on a circle and a rectangle but not with this custom shape. – Maxim Toyberman Jul 02 '19 at 13:24
  • Where do you get the custom shape from? Are you drawing it using the `canvas` and a `Path` or is that a transparent image with the shape drawn on white pixels? – Martin Marconcini Jul 02 '19 at 13:38
  • @MartinMarconcini it is a transparent image with the shape drawn on white pixels – Maxim Toyberman Jul 02 '19 at 13:43
  • And what's the blueish tone? – Martin Marconcini Jul 02 '19 at 13:44
  • @MartinMarconcini this is the background of the RelativeLayout, The face Image is inside the layout – Maxim Toyberman Jul 02 '19 at 13:48
  • I think it may be best if you expand your question to include the layout and how you're displaying this, because of two reasons: 1. I may not know how to help you in this scenario (I thought you were doing something different) and 2. Someone else might, and I can see how it would be very important to have the XMLs and some code beforehand. – Martin Marconcini Jul 02 '19 at 13:51
  • @MartinMarconcini I have added the XML , I have also tried to create a custom view, i am not sure what is the right approach. – Maxim Toyberman Jul 02 '19 at 13:58

0 Answers0