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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:31:09+00:00 2026-06-02T10:31:09+00:00

I tried to do something to compare 2 bitmaps in the Finger Paints application.

  • 0

I tried to do something to compare 2 bitmaps in the Finger Paints application. I first load the first bitmap into a 2d array, then i want to load the other output bitmap from finger paint into another array and compare both bitmap. My code doesn’t work and i have no idea where should i edit. The compare function start right after the user press the “compare” option in the option menu. Please help me.

public class MainActivity extends GraphicsActivity
    {

boolean check = false;  


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new MyView(this));

    mPaint = new Paint();                                                                       
    mPaint.setAntiAlias(true);                                          
    mPaint.setDither(true);                                             
    mPaint.setColor(Color.RED);                                         
    mPaint.setStyle(Paint.Style.STROKE);                                
    mPaint.setStrokeJoin(Paint.Join.ROUND);                             
    mPaint.setStrokeCap(Paint.Cap.ROUND);                               
    mPaint.setStrokeWidth(20);
}

private Paint   mPaint;

public class MyView extends View {
    Bitmap mBitmap;
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.c_1);
    Bitmap bitmap2;
    private Canvas  mCanvas;
    private Path    mPath;
    private Paint   mBitmapPaint;

    int w1 = bitmap.getWidth();
    int h1 = bitmap.getHeight();

    int [][] array = new int [w1][h1];
    int b=0;
    int c=0;
    int k=0;
    int i, j;
    int l=0;
    View content = this;


    {
        for(int j = 0;j< w1; j++){
            for(int i = 0;i< h1; i++,k++){
                array[j][i]= bitmap.getPixel(j, i);
                if(bitmap.getPixel(j, i)== 100);
                {
                    b++;
                }

            }
        }
        System.out.println("numbers of gray:" + b);       

    }


    public MyView(Context c) {                                              
        super(c);

        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);
        content.setDrawingCacheEnabled(true);
        content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

}

    @Override
    public void onSizeChanged(int w, int h, int oldw, int oldh){
        super.onSizeChanged(w, h, oldw, oldh);
        mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }


    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.WHITE);

        canvas.drawBitmap(bitmap, 0, 0, null);

        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

        canvas.drawPath(mPath, mPaint);

        bitmap2 = content.getDrawingCache();
    }




    private float mX, mY;
    private static final float TOUCH_TOLERANCE = 4;

    private void touch_start(float x, float y) {
            mPath.reset();
            mPath.moveTo(x, y);
            mX = x;
            mY = y;

        }
    private void touch_move(float x, float y) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
            mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
            mX = x;
            mY = y;
            }
    }
    private void touch_up() {
        mPath.lineTo(mX, mY);
        mCanvas.drawPath(mPath, mPaint);
        mPath.reset();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        float x = event.getX();
        float y = event.getY();         

        System.out.println("Coordinates:" + x + "," + y);

    switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                touch_start(x, y);
                invalidate();
                break;
            case MotionEvent.ACTION_MOVE:
                touch_move(x, y);
                invalidate();
                break;
            case MotionEvent.ACTION_UP:
                touch_up();
                invalidate();
                break;
    }                               

    return true;    

    }  

    private void compare(Boolean check){
    if(check == true)
        {

            int w2 = bitmap2.getWidth();
            int h2 = bitmap2.getHeight();
            System.out.println("Width and Height of the product:" + w2 + "," + h2); 

            int [][] array1 = new int [w2][h2];             
            {               
                for(int j1 = 0;j1< w2; j1++){
                    for(int i1 = 0;i1< h2; i1++,l++){
                        array1[j1][i1]= bitmap2.getPixel(j1, i1);
                        if(array[j1][i1]== 100 && array1[j1][i1] == Color.RED);
                        {
                            c++;
                        }

                    }
                }
                System.out.println("numbers pixels touched:" + c);       
            }
            int d=(b-c)/b*100;

            Toast t = Toast.makeText(getBaseContext(), "Completion :" + d + "%", Toast.LENGTH_SHORT);
            t.show();

        }
    }
}

private static final int CLEAR_MENU_ID = Menu.FIRST;
private static final int COMPARE_ID = Menu.FIRST + 1;

public boolean onCreateOptionsMenu(Menu menu)  {
    super.onCreateOptionsMenu(menu);

    menu.add(0, CLEAR_MENU_ID, 0, "Clear ALL");
    menu.add(0, COMPARE_ID, 0, "Compare");

 return true;
   }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case CLEAR_MENU_ID:
            setContentView(new MyView(this));
            check = false;
            return true;
        case COMPARE_ID:
            check = true;
            return true;
    }
            return super.onOptionsItemSelected(item);   
    }
}
  • 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-02T10:31:10+00:00Added an answer on June 2, 2026 at 10:31 am

    You’re not calling compare() anywhere.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    
        switch (item.getItemId()) {
            case CLEAR_MENU_ID:
                setContentView(new MyView(this));
                check = false;
                return true;
            case COMPARE_ID:
                check = true;
                compare(check);
                return true;
            default:
                break;
        }
    
        return super.onOptionsItemSelected(item);   
    
    }
    

    I can’t see the purpose of the “check” variable but I assume that you are using it somewhere else.

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

Sidebar

Related Questions

How can I access the array to fetch the email address? I tried something
First time when I tried to do something in WPF, I was puzzled with
I tried setting all possible styles to something other than grey, just to try
Today I encountered something strange: I tried to put a utility method into an
I want to do something like this: I tried to implement it by myself
How can I compare image sizes? I tried doing something like this: if (image1.image.size
In my application I should compare two source code files to see if something
I tried something like this but it just makes the background of the image
I tried something like: RadioButton[] diff = new RadioButton[10]; for (int i = 0;
I'm still rather new to iPhone development and I tried something I didn't it

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.