AndroidGenius
AndroidGenius

Reputation: 101

Applying a colorFilter On Image

This is probably a stupid question but I have been searching for hours but didn't reach any conclusion on how i should do it.

There is a dark filter which is applied on images on some websites and apps images. My question is that how should i produce this filter and apply it on image on runtime. I know it is somehow related to using setColorFilter but i am not sure how. If someone can guide me in the right direction , that's all i need. Thank you

Example Image Filter:

enter image description here

Upvotes: 0

Views: 59

Answers (1)

betorcs
betorcs

Reputation: 2831

It's a sample how i use to do it.

<RelativeLayout
        android:clickable="true"
        android:foreground="?attr/selectableItemBackground"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- Here, you can implement your own imageview as you want -->
        <my.package.ui.widget.ScaleImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="matrix"
            android:adjustViewBounds="true"
            app:error="@{@drawable/image_broken}"
            app:imageUrl="@{item.imageUrl}"
            app:placeholder="@{@drawable/image_holder}" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#30000000" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="40dp"
            android:ellipsize="end"
            android:lines="1"
            android:shadowColor="#111"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowRadius="1"
            android:text="@{item.title}"
            android:textColor="#fff"
            style="@style/TextAppearance.AppCompat.Title"
            tools:text="It's Image Caption" />

    </RelativeLayout>

Upvotes: 1

Related Questions