0

I have a bitmap drawn to a canvas that I want to be able to paint transparent onto. When I move my finger to do the drawing, the paint does not paint to where my finger is. Instead it paints below and to the right of where I am touching.

@Override
    public void onDraw(Canvas canvas) {
        canvas.drawColor(Color.TRANSPARENT);
        bitmapCanvas.drawColor(Color.TRANSPARENT);
        bitmapCanvas.drawCircle(x, y, 40, eraserPaint);

        Matrix matrix = new Matrix();
        matrix.postTranslate(tattoo.getX(), tattoo.getY());

        canvas.drawBitmap(bitmap, matrix, paint);
    }

    public boolean onTouch(View view, MotionEvent event) {
        x = (int) event.getX();
        y = (int) event.getY();

        invalidate();
        return true;
    }
  • You've got a translate matrix on the `Bitmap` you're drawing to the `View`'s `Canvas`. I can't be sure what that's meant for, just from the given code, but if you're trying to account for the `View`'s offset, you don't need to. The coordinates of the touch event are relative to the `View` itself. – Mike M. Nov 14 '16 at 04:11
  • I have an activity where a user can position an image. A view with a canvas gets super imposed over the view where I want the users to be able to paint over the image. The new draw view is set to match parent, so it has the same dimensions as the original view. Everything works fine, except the coordinates that the ontouch registers., –  Nov 14 '16 at 21:39
  • Well, the details of your setup still aren't very clear. What isn't drawing in the right spot, exactly? The circle? The `Bitmap`? Both? Which `Bitmap` is backing `bitmapCanvas`? Is it `bitmap`? What is `bitmap`'s function? What is `tattoo`, and why are you translating by its x,y? In any case, I would mention that a `Bitmap` is drawn from its top left corner, so if you're expecting it to be centered on a particular x,y, you need to account for the `Bitmap`'s dimensions. – Mike M. Nov 15 '16 at 01:49

0 Answers0