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 5965585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:39:10+00:00 2026-05-22T19:39:10+00:00

i want to test ColorMatrix,my code is : public class testColorMatrix extends Activity {

  • 0

i want to test ColorMatrix,my code is :

    public class testColorMatrix extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new SampleView(this));
    }

    private static class SampleView extends View{

        BitmapFactory.Options options;
        Bitmap grayscale;
        Bitmap alpha;
        Paint grayToAlpha;
        Canvas alphaCanvas;
        float[] matrix;
        public SampleView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            // TODO Auto-generated constructor stub
            init();
        }

        public SampleView(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
            init();
        }

        public SampleView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
            init();
        }
        public void init(){
             options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            options.inScaled = false;

            // Load source grayscale bitmap
             grayscale = BitmapFactory.decodeResource(getResources(), R.drawable.a2, options);
            // Place for  alpha mask. It's specifically ARGB_8888 not ALPHA_8, 
            // ALPHA_8 for some reason didn't work out for me. 
             alpha = Bitmap.createBitmap(grayscale.getWidth(), grayscale.getHeight(),
                    Bitmap.Config.ARGB_8888);
             matrix = new float[] {
                    5, 0, 0, 0, 10,
                    0, 5, 0, 0, 10,
                    0, 0, 5, 0, 0,
                    0, 0, 0, 1, 0};
             grayToAlpha = new Paint();

        }

        @Override
        protected void onDraw(Canvas canvas) {

            grayToAlpha.setColorFilter(null);
            canvas.drawBitmap(grayscale, 0, 0, grayToAlpha); 
            grayToAlpha.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(matrix)));
        //    alphaCanvas = new Canvas(alpha);
            // TODO Auto-generated method stub
            //super.onDraw(canvas);
        // Make sure nothing gets scaled during drawing
         alphaCanvas.setDensity(Bitmap.DENSITY_NONE);
         // Draw grayscale bitmap on to alpha canvas, using color filter that
         // takes alpha from red channel
         alphaCanvas.drawBitmap(grayscale, 0, 0, grayToAlpha);
         // Bitmap alpha now has usable alpha channel!

        }
    }
}

but it cannot run ,ddms it give me:

05-26 02:46:18.582: ERROR/AndroidRuntime(924): ERROR: thread attach failed

05-26 02:46:29.121: ERROR/gralloc(52): [unregister] handle 0x4422f8 still locked (state=40000001)

can you give some advice to find the mistake.

  • 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-05-22T19:39:11+00:00Added an answer on May 22, 2026 at 7:39 pm

    i also solve my question: modify as follows

    @Override
        protected void onDraw(Canvas canvas) {
    
            grayToAlpha.setColorFilter(null);
            canvas.drawBitmap(grayscale, 0, 0, grayToAlpha); 
            canvas.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(matrix)));
        //    alphaCanvas = new Canvas(alpha);
            // TODO Auto-generated method stub
            //super.onDraw(canvas);
        // Make sure nothing gets scaled during drawing
         canvas.setDensity(Bitmap.DENSITY_NONE);
         // Draw grayscale bitmap on to alpha canvas, using color filter that
         // takes alpha from red channel
         canvas.drawBitmap(grayscale, 0, 0, grayToAlpha);
         // Bitmap alpha now has usable alpha channel!
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to test a piece of code that uses network (the NSURLConnection class,
I want to test the behavior of a certain piece of .NET code in
I have a method like public abstract class Base { public void MethodUnderTest(); }
I want to test the profile usage of an important library-class of my rails-project.
I want to test the functionality of an activity that contains a ListFragment ,
I want to test some methods that call others in the same class. They
I want to test my RESTful resource in Rails: require 'rubygems' require 'activeresource' class
I want to test the new type-checking bytecode verifier with classes created by scalac
I want to test the behavior of a first-time app install with regard to
I want to test my Dao Class using the SpringContextTests. In my method class

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.