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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:45:06+00:00 2026-05-25T03:45:06+00:00

In my Android Finger Paint app I used two view’s imageview backside and paintview

  • 0

In my Android Finger Paint app I used two view’s imageview backside and paintview on top, it’s working fine for painting and erasing. But after saving the real painting position is changed.

removed dead links to images

Code is

public MyView(Context c)  {
    super(c);
    //mBitmap = Bitmap.createScaledBitmap(originalBitmap,bw,bh,true);
    mBitmap = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
}
@Override 
protected void onDraw(Canvas canvas) {   
    canvas.drawColor(Color.TRANSPARENT);
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mPath, mPaint);
} 

myimage.setOnTouchListener(this);
public boolean onTouch(View v, MotionEvent event) {
    ImageView myimage = (ImageView) v;
    // Dump touch event to log
    dumpEvent(event);
    // Handle touch events here...
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            savedMatrix.set(matrix);
            start.set(event.getX(), event.getY());
            Log.d(TAG, "mode=DRAG");
            mode = DRAG;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            oldDist = spacing(event);
            Log.d(TAG, "oldDist=" + oldDist);
            if (oldDist > 10f) {
                savedMatrix.set(matrix);
                midPoint(mid, event);
                mode = ZOOM;
                Log.d(TAG, "mode=ZOOM");
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            Log.d(TAG, "mode=NONE");
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                /////// limiting  the panning 
                matrix.getValues(matrixValues);
                float currentY = matrixValues[Matrix.MTRANS_Y];
                float currentX = matrixValues[Matrix.MTRANS_X];
                float currentScale = matrixValues[Matrix.MSCALE_X];
                float currentHeight = height * currentScale;
                float currentWidth = width * currentScale;
                float dx = event.getX() - start.x;
                float dy = event.getY() - start.y;
                float newX = currentX+dx;
                float newY = currentY+dy;   
                RectF drawingRect = new RectF(newX, newY, newX+currentWidth, newY+currentHeight);
                float diffUp = Math.min(viewRect.bottom-drawingRect.bottom, viewRect.top-drawingRect.top);
                float diffDown = Math.max(viewRect.bottom-drawingRect.bottom, viewRect.top-drawingRect.top);
                float diffLeft = Math.min(viewRect.left-drawingRect.left, viewRect.right-drawingRect.right);
                float diffRight = Math.max(viewRect.left-drawingRect.left, viewRect.right-drawingRect.right);
                if(diffUp > 0 ){ dy +=diffUp; }
                if(diffDown < 0){ dy +=diffDown; }  
                if( diffLeft> 0){ dx += diffLeft; }
                if(diffRight < 0){dx += diffRight; }
                matrix.postTranslate(dx, dy);
            } 
            else if (mode == ZOOM) {
                float newDist = spacing(event);
                Log.d(TAG, "newDist=" + newDist);
                if (newDist > 10f) {
                matrix.set(savedMatrix);
                float scale = newDist / oldDist;
                matrix.getValues(matrixValues);
                float currentScale = matrixValues[Matrix.MSCALE_X];
                // limit zoom
                if (scale * currentScale > maxZoom) {
                    scale = maxZoom / currentScale; 
                }
                else if(scale * currentScale < minZoom){
                    scale = minZoom / currentScale; 
                }
                matrix.postScale(scale, scale, mid.x, mid.y);
            }
        }
        break;
    }
    myimage.setImageMatrix(matrix);
    return true; // indicate event was handled
}

// Show an event in the LogCat view, for debugging 
private void dumpEvent(MotionEvent event) {
    String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE",
                      "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
    StringBuilder sb = new StringBuilder();
    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    sb.append("event ACTION_").append(names[actionCode]);
    if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode ==   MotionEvent.ACTION_POINTER_UP) {
        sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
        sb.append(")");
    }
    sb.append("[");
    for (int i = 0; i < event.getPointerCount(); i++) {
        sb.append("#").append(i);
        sb.append("(pid ").append(event.getPointerId(i));
        sb.append(")=").append((int) event.getX(i));
        sb.append(",").append((int) event.getY(i));
        if (i + 1 < event.getPointerCount())
            sb.append(";");
        }
        sb.append("]");
        Log.d(TAG, sb.toString());
    }

    //Determine the space between the first two fingers
    private float spacing(MotionEvent event) {
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return FloatMath.sqrt(x * x + y * y);
    }

    // Calculate the mid point of the first two fingers 
    private void midPoint(PointF point, MotionEvent event) {
        float x = event.getX(0) + event.getX(1);
        float y = event.getY(0) + event.getY(1);
        point.set(x / 2, y / 2);
    }
}
  • 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-25T03:45:07+00:00Added an answer on May 25, 2026 at 3:45 am

    The position does not change! If you look closely at your linked images, you’ll see that your fingerpainting does not move relative to the corner of the photo. In other words, you are saving the drawings’ positions relative to the screen rather than relative to the current scroll position of the photo.

    When you save, you have to take into account the fact that the background photo is cropped and/or scaled.

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

Sidebar

Related Questions

I am new to android,i prepared one painting view using finger with help of
So I'm making a simple painting app for the Android SDK. However, the onTouchEvent()
I am trying to create an android application same as finger paint on the
I'm working on a painting application for Android and I'd like to use raw
I am working on a paint application for Android. Now I want to implement
Android comes with lots of system resources ( android.R ) that can be used
I am trying develop an Android app which uses Google maps. So for the
I want to capture the finger movement direction on Android touch phone. If a
I am doing one application using proximity sensor in android. when any object(finger) comes
i am trying to select text in android web view with the follow method

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.