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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:54:54+00:00 2026-05-27T18:54:54+00:00

I need to draw a circle as per my finger move so i have

  • 0

I need to draw a circle as per my finger move so i have write this code

package com.sport;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class sport extends Activity {

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

    }

    class TouchView extends View {
        Bitmap bgr;
        Bitmap overlayDefault;
        Bitmap overlay;
        Paint pTouch;

        int X;
        int Y;
        Canvas c2;

        public TouchView(Context context) {
            super(context);

            bgr = BitmapFactory.decodeResource(getResources(), R.drawable.new1);
            overlayDefault = BitmapFactory.decodeResource(getResources(),
                    R.drawable.original);
            overlay = BitmapFactory.decodeResource(getResources(),
                    R.drawable.new1).copy(Config.ARGB_8888, true);
            c2 = new Canvas(overlay);

            pTouch = new Paint(Paint.DEV_KERN_TEXT_FLAG);
            pTouch.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
            pTouch.setColor(Color.TRANSPARENT);
            // pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
            DisplayMetrics displaymetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            int ht = displaymetrics.heightPixels;
            int wt = displaymetrics.widthPixels;

            X = wt / 2;
            Y = 0;

        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {

            switch (ev.getAction()) {

            case MotionEvent.ACTION_DOWN: {

                X = (int) ev.getX();
                Y = (int) ev.getY();
                //invalidate();

                break;
            }

            case MotionEvent.ACTION_MOVE: {

                X = (int) ev.getX();
                Y = (int) ev.getY();
                /* Toast.makeText(getBaseContext(),"x is::"+ X,
                          Toast.LENGTH_LONG).show();
                          Toast.makeText(getBaseContext(),"Y is::"+ Y,
                         Toast.LENGTH_LONG).show();*/
                          //c2.drawCircle(X, Y, 70, pTouch);

                /*System.out.println("x is"+X);
                System.out.println("Y is"+Y);*/
                invalidate();
                break;

            }

            case MotionEvent.ACTION_UP:
                X = (int) ev.getX();
                Y = (int) ev.getY();
                /*
                 * Toast.makeText(getBaseContext(),"x is::"+ X,
                 * Toast.LENGTH_LONG).show();
                 * Toast.makeText(getBaseContext(),"Y is::"+ Y,
                 * Toast.LENGTH_LONG).show();
                 */
                //invalidate();
                break;
            case MotionEvent.ACTION_POINTER_ID_MASK :
                /*X = (int) ev.getX();
                Y = (int) ev.getY();



                invalidate();*/
                break;
            }

            return true;
        }

        @Override
        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            DisplayMetrics displaymetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            int ht = displaymetrics.heightPixels;
            int wt = displaymetrics.widthPixels;
            int heightbitmap = bgr.getHeight();
            int widthbitmap = bgr.getWidth();
            int minus = wt - widthbitmap;

            // draw background
            canvas.drawBitmap(bgr, minus / 2, 0, null);
            // copy the default overlay into temporary overlay and punch a hole
            // in it
            c2.drawBitmap(overlayDefault, 360, 0, null); // exclude this line to
                                                            // show all as you
            Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.diff_6);                                              // draw

            //c2.drawBitmap(_scratch, 10, 10, pTouch);
            if(X >= 470 & X <= 522)
            {
                if(Y >= 255 & Y<= 330)
                {   
                //c2.drawRect(X, Y, 5, 5, pTouch);
                    double outer_radius = 0.5 * Math.sqrt((_scratch.getWidth()) * (_scratch.getWidth())+ (_scratch.getHeight()) * (_scratch.getHeight()));  
                 float f = (float) outer_radius;


                    c2.drawCircle(X, Y, f, pTouch);
                }

            }   


            // draw the overlay over the background
            canvas.drawBitmap(overlay, minus/2, 0, null);

        }

    }

}

Problem::
when i touch on screen circle are stay at right side of my finger Like this.
enter image description here but i need it center of my finger please help on this

  • 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-27T18:54:54+00:00Added an answer on May 27, 2026 at 6:54 pm

    The problem is because you create ‘overlay’ with respect to the x and y cordinates from the touch event and later copying this onto the background with an offset (minus/2). Assuming your background image is smaller than the screen resolution the circle will always shift right and hence will look the circle is at the right of your finger.

    If you use a background image which has same resolution as the screen dimensions , you will get properly drawn circle, with its centre at the point of touch.

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

Sidebar

Related Questions

I have recently started working with Android, And I need to draw a Circle
I need to draw a circle in google Maps V3 but I have 2
I need to draw a part of a perfect circle using graphics.curveTo (I have
I need to draw a circle onto a bitmap in a specific colour given
I need to draw a rectange,circle and line and then animate them(press left ->
I need to draw on a TPanel, ideally directly so I don't have another
On every mouse move I need to draw on my canvas a radial gradient
I need to draw a circle to display the distance around a point that
I have a map custom view that inherit from MKOverlayPathView. I need this custom
I need to draw a circle around a vertex in JUNG . The circle

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.