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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:48:07+00:00 2026-05-23T15:48:07+00:00

I loaded the first bitmap (image1) on the canvas i.e. sized 320 X 312.

  • 0

I loaded the first bitmap (image1) on the canvas i.e. sized 320 X
312. The second bitmap (image2) is 41 X 41 loaded at x,y – 235, 147.
Overlapped on top of the image1. Now when I do a draw line from x,y –
174, 254 to x,y – 249, 177 in the touch event. The lineTo destination
249, 177 is “underneath” the image2 drawn at 235,147 thus the last 14
or so pixels of the drawn line is hidden under image2. I hope I
explained this clearly. How do I get the full line length to show?

    public GameView(Context context) {
            super(context);
            setFocusable(true);

            bMap = BitmapFactory.decodeResource(getResources(),
                R.drawable.image1);
            bMapMutable = bMap.copy(Bitmap.Config.ARGB_8888, true);
            mCanvas = new Canvas();

            mPath = new Path();

            bMap2 = BitmapFactory.decodeResource(getResources(),
                R.drawable.image2);
            bMapMutable2 = bMap2.copy(Bitmap.Config.ARGB_8888, true);

    }

    @Override
    protected void onDraw(Canvas canvas) {
            canvas.drawBitmap(bMapMutable, 0, 0, null);

            float left = (float) ((scale == 1) ? 235 : 235 * 1.5);
            float top = (float) ((scale == 1) ? 147 : 147 * 1.5);

            canvas.drawBitmap(bMapMutable2, left, top, null);

            canvas.drawPath(mPath, mPaint);

    }

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

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                    if (touchCount <= 2)
                    {
                        touchCount += 1;
                        touch_start(x, y);
                        invalidate();

                    }

                    if (touchCount == 2)
                    {
                            if (scale == 1.0)
                            {
                                mPath.moveTo(174,254);
                            }
                            else
                            {
                                mPath.moveTo(261,381);
                            }

                            if (scale == 1.0)
                                    mPath.lineTo(249, 177);
                            else
                                    mPath.lineTo(374, 266);

                            mCanvas.drawPath(mPath, mPaint);
                            mPath.reset();
                            touchCount = 0;
                    }

                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return true;
    }

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

        if (touchCount == 1)
        {
                mX = x;
                mY = y;
        }
        else
        {
            mX2 = x;
                mY2 = y;
        }
    } 
  • 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-23T15:48:08+00:00Added an answer on May 23, 2026 at 3:48 pm

    Instead of drawing the path in your onTouchEvent method, let the onDraw method do it and keep the contents of mPath as your line’s path then call invalidate() to make it redraw with new information. Every time onDraw is called on its own, the path will then be drawn last (as you have it).

    To clarify, instead of doing this:

    mCanvas.drawPath(mPath, mPaint);
    mPath.reset();
    

    Do:

    invalidate();
    

    Your onDraw method is already correctly going to draw them in the correct order.

    To later remove the line, do:

    mPath.reset();
    invalidate();
    

    And the onDraw will redraw without the line.

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

Sidebar

Related Questions

My .NET 2.0 application imports unmanaged 32 bit dll. The dll is loaded (first
I have two BufferedImages I loaded in from pngs. The first contains an image,
Given two app domain : in the first, Library1 and CommonLibrary are loaded. In
I have a web app that is heavily loaded in javascript and css. First
I have some images that I loaded from a remote source stored in Bitmap
I need to set/get the cookies stored at first.example while browsing second.example , I
I have to draw a bitmap multiple times. It's loaded from file. I can
I'm working on my first WP7 app and now I'm exploring the world of
I'm trying to display 2 images on a canvas. I've loaded one, and it
I want my windows form to be loaded first, render its children and all.

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.