christophesmet / android_maskable_layout

A library that easily allows you to mask layouts/viewgroups
Apache License 2.0
652 stars 145 forks source link

Use B&W Mask #37

Closed dacastro4 closed 5 years ago

dacastro4 commented 5 years ago

Hey! I just need some help because I'm trying to use a mask that is a JPEG file that has white background and the mask part is black. It kinda works but how can I change the color of the mask? I tried applying backgroundTint but It didn't work. This is what I have.

<com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout
            android:id="@+id/car_bg_base_mask"
            app:porterduffxfermode="OVERLAY"
            app:mask="@drawable/m3_overlay"
            android:elevation="-1dp"
            android:backgroundTint="@color/blue"
            android:layout_height="match_parent"
            android:layout_width="match_parent">

            <ImageView
                android:id="@+id/car_bg_base"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/car_background"/>

        </com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout>
christophesmet commented 5 years ago

Why would you want to colour the mask? Could you provide an image of the result you are trying to achieve? I'm not sure what the end goal is.

dacastro4 commented 5 years ago

To change the color of the image. Sure: Having this image: image and this mask: mask result: result

I can accomplish this on Affinity Designer by adding color to the mask but I have to do it programatically because the masks and the colors change.

christophesmet commented 5 years ago

I think in order for this to work you have to color your mask. Give the color pixels an alpha of 255 and the transparent ones an alpha of 0. Then it should be properly masked. I really think you need to color your mask. Is there a sample project where I can test this to ?

dacastro4 commented 5 years ago

@christophesmet no, I don't have a sample project. I'm gonna try painting the mask before.