Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:30:06+00:00 2026-06-10T02:30:06+00:00

I have an ImageView with bitmap in it. This bitmap has alpha channel and

  • 0

I have an ImageView with bitmap in it. This bitmap has alpha channel and transparent pixels.
When i try to use ColorFiter with Mode.OVERLAY (since honeycomb) – provided color overlay the whole imageview (whole rect), but i want only to overlay non transparent pixels. How can i clip the imageview’s canvas to perform filter where i want ?

UPDATED

I have grey image in png:

enter image description here

When i try to use MODE_ATOP i get:

enter image description here

When i use OVERLAY i get:

enter image description here

And what i want to get:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:30:08+00:00Added an answer on June 10, 2026 at 2:30 am

    There’s probably a more efficient way to do this (maybe by creating a ColorMatrixColorFilter to approximate it), but since Mode.OVERLAY appear to be hard to simplify otherwise, here’s some sample code that should implement what you want:

    public class MyActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            final ImageView imageView = new ImageView(this);
            setContentView(imageView);
    
            final Paint paint = new Paint();
            Canvas c;
    
            final Bitmap src = BitmapFactory.decodeResource(getResources(),
                    android.R.drawable.sym_def_app_icon);
            final int overlayColor = Color.RED;
    
            final Bitmap bm1 = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Config.ARGB_8888);
            c = new Canvas(bm1);
            paint.setColorFilter(new PorterDuffColorFilter(overlayColor, PorterDuff.Mode.OVERLAY));
            c.drawBitmap(src, 0, 0, paint);
    
            final Bitmap bm2 = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Config.ARGB_8888);
            c = new Canvas(bm2);
            paint.setColorFilter(new PorterDuffColorFilter(overlayColor, PorterDuff.Mode.SRC_ATOP));
            c.drawBitmap(src, 0, 0, paint);
    
            paint.setColorFilter(null);
            paint.setXfermode(new AvoidXfermode(overlayColor, 0, Mode.TARGET));
            c.drawBitmap(bm1, 0, 0, paint);
    
            imageView.setImageBitmap(bm2);
        }
    
    }
    

    In short, we draw the source bitmap and color using the OVERLAY mode, and then using a secondary bitmap (composited using SRC_ATOP mode), we combine it using AvoidXfermode to not draw over the transparent pixels.

    Original image:

    original image

    Result:

    result

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a code like this Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.correct); newImg = (ImageView)findViewById(R.id.rwans);
This has me baffled. I need to copy the Bitmap from one ImageView into
I have imageView in activity. How I can set position this imageView in my
I have this ImageView in my layout: <ImageView android:layout_width=fill_parent android:layout_height=wrap_content android:contentDescription=@string/image_divider android:paddingBottom=8dp android:paddingTop=4dp android:scaleType=fitXY
I have a Imageview in main.xml, how to set the bitmap the to the
Scope Image bitmap have to be shown as imageView.setImageBitmap(bitmap) and scaled to fit UI.
I have done this in an Activity and it works perfectly. ImageView myImage =
I'm using this code to get the bitmap placed inside the ImageView] private Bitmap
I have an activity which has an ImageView in it. What I want to
I have a ImageView which shows a picture that has been taken from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.