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

  • Home
  • SEARCH
  • 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 998621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:13:34+00:00 2026-05-16T07:13:34+00:00

public class DrawView extends View { private ColorBall[] colorballs = new ColorBall[3]; // array

  • 0
public class DrawView extends View
{
   private ColorBall[] colorballs = new ColorBall[3]; // array that holds the balls
   private int balID = 0; // variable to know what ball is being dragged

      /* protected Bitmap getImage(int id) {
        return BitmapFactory.decodeResource(mContex.getResources(), id);
    }*/
   private Paint mBitmapPaint = new Paint();
  public DrawView(Context context) {
        super(context);
        setFocusable(false); //necessary for getting the touch events

        // setting the start point for the balls
        Point point1 = new Point();
        point1.x = 50;
        point1.y = 400;
        Point point2 = new Point();
        point2.x = 100;
        point2.y = 400;
        Point point3 = new Point();
        point3.x = 150;
        point3.y = 400;


        // declare each ball with the ColorBall class
        colorballs[0] = new ColorBall(context,R.drawable.b, point1);
       colorballs[2] = new ColorBall(context,R.drawable.t, point3);


    }

    // the method that draws the balls
    @Override protected void onDraw(Canvas canvas) {
        canvas.drawColor(0xFFCCCCCC);
        setFocusable(false);
        Log.v("Images","3333");
        //if you want another background color       
        canvas.drawBitmap((BitmapFactory.decodeResource(getResources(),R.drawable.caralpha)), 10, -50, mBitmapPaint);
        //draw the balls on the canvas
        for (ColorBall ball : colorballs) {
            canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), null);
          }
        //canvas.drawRect(10, 50, 10 + 2, 10 + 2,mBitmapPaint);
        canvas.drawText("A", 10,350, mBitmapPaint);


        Vector correctname=correct("B");

        String name="b";



        for(int i=0,xCo=20;i<correctname.size();i++)
        {
          try {
            int image=selectImage(name.charAt(i));
            canvas.drawBitmap((BitmapFactory.decodeResource(getResources(),image)), 10+xCo,350, mBitmapPaint);
            xCo=xCo+100;
          }
          catch(Exception e)
          {

          }
        }
    }

    private int selectImage(char charAt) {
        switch(charAt)
        {
        case 'a':
            return R.drawable.a;
        case 'b':
            return R.drawable.b;
        case 't':
            return R.drawable.t;

        }
        return 0;

    }

    private Vector correct(String word) {
         Vector al = new Vector();
            for (int i = 0; i < word.length(); i++) 
            {
            al.add(word.charAt(i));
            }
            al.toString();
            return al;
    }

    // events when touching the screen
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 

        int X = (int)event.getX(); 
        int Y = (int)event.getY(); 

        switch (eventaction ) { 

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
            balID = 0;
            for (ColorBall ball : colorballs) {
                // check if inside the bounds of the ball (circle)
                // get the center for the ball
                int centerX = ball.getX() + 25;
                int centerY = ball.getY() + 25;

                // calculate the radius from the touch to the center of the ball
                double radCircle  = Math.sqrt( (double) (((centerX-X)*(centerX-X)) + (centerY-Y)*(centerY-Y)));

                // if the radius is smaller then 23 (radius of a ball is 22), then it must be on the ball
                if (radCircle < 23){
                    balID = ball.getID();
                    break;
                }

                // check all the bounds of the ball (square)
                //if (X > ball.getX() && X < ball.getX()+50 && Y > ball.getY() && Y < ball.getY()+50){
                //  balID = ball.getID();
                //  break;
                //}
              }

             break; 


        case MotionEvent.ACTION_MOVE:   // touch drag with the ball
            // move the balls the same as the finger
            if (balID > 0) {
                Log.v("Images","3333  Moving");
                colorballs[balID-1].setX(X-25);
                colorballs[balID-1].setY(Y-25);
            }

            break; 

        case MotionEvent.ACTION_UP: 
            /*for (ColorBall ball : colorballs) {
                Log.v("y value","YYYYYYYYYYY  "+ball.getY()+"XXXXXXXXXXXX "+ball.getID());
            }*/


            // touch drop - just do things here after dropping
//setFocusable(false);
             break; 
        } 
        // redraw the canvas
        invalidate(); 
        return true; 

    }
}

Hi I am using the above code for displaying bitmap.and i also move that bitmap.Now my qusetion is how i am compare bitmap with another bitmap.
Please give me some suggestions.Thanks in advance

  • 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-16T07:13:34+00:00Added an answer on May 16, 2026 at 7:13 am

    “collision detection” is what you should look after. There are infinite algorithms for that out there.. one on SO: Collision Detection between two images in Java

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

Sidebar

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.