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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:58:20+00:00 2026-06-17T10:58:20+00:00

This is the code I’m using to convert two colored pictures to grayscale and

  • 0

This is the code I’m using to convert two colored pictures to grayscale and compare them pixel by pixel. My app keeps force closing though. here’s the code:

public boolean equals(Bitmap bitmap1, Bitmap bitmap2) {
        Bitmap grayscaleBitmap1 = Bitmap.createBitmap(
                bitmap1.getWidth(), bitmap1.getHeight(),
                Bitmap.Config.RGB_565);

            Canvas c = new Canvas(grayscaleBitmap1);
            Paint p = new Paint();
            ColorMatrix cm = new ColorMatrix();

            cm.setSaturation(0);
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
            p.setColorFilter(filter); 
            c.drawBitmap(bitmap1, 0, 0, p); 
            Bitmap grayscaleBitmap2 = Bitmap.createBitmap(
                    bitmap2.getWidth(), bitmap2.getHeight(),
                    Bitmap.Config.RGB_565);
            Canvas c1 = new Canvas(grayscaleBitmap2);
            c1.drawBitmap(bitmap2, 0, 0, p);    
        ByteBuffer buffer1 = ByteBuffer.allocate(grayscaleBitmap1.getHeight()
                * grayscaleBitmap1.getRowBytes());
        grayscaleBitmap1.copyPixelsToBuffer(buffer1);

        ByteBuffer buffer2 = ByteBuffer.allocate(grayscaleBitmap2.getHeight()
                * grayscaleBitmap2.getRowBytes());
        grayscaleBitmap2.copyPixelsToBuffer(buffer2);

        return Arrays.equals(buffer1.array(), buffer2.array());
    }

Here’s the logcat.

  • 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-17T10:58:21+00:00Added an answer on June 17, 2026 at 10:58 am
    01-12 10:12:48.947: E/AndroidRuntime(2052): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    01-12 10:12:48.947: E/AndroidRuntime(2052):     at android.os.Handler.<init>(Handler.java:121)
    01-12 10:12:48.947: E/AndroidRuntime(2052):     at android.widget.Toast.<init>(Toast.java:68)
    

    These lines says that you have wrote Toast somewhere in your async Task.
    please put your Toast into
    runOnUiThread(); as i shown below :

      runOnUiThread(new Runnable() {        
                @Override
                public void run() {
                Toast.makeText(yourActivity.this, "your Text Here!",1000).show();                               
                }
        });
    

    and you are done.

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

Sidebar

Related Questions

This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
This code comes from: http://code.activestate.com/recipes/577090-file-encryption-using-stream-cipher/ import sys import random if len(sys.argv) != 4: print
This code works fine after commenting statement one. Statement two gives some garbage value
This code seems to work as expected, populates an array of numbers using a
This code separates a string into tokens and stores them in an array of
This code just keeps giving me errors. I have a field (datetime) in my
This code selects cell values in MySQL and manually adds them to PHP variables:
this code using an OLEDB source will populate the OutputColumnCollection below it, the code
This code works properly in my localhost. I am using xampp 1.7.3. but when
This code reads an array of files and should pass them through to 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.