0

i have been struggling doing a onDraw with photoview. I used another class to extend photoview and override the onDraw. I get the drawable and show it on the extended class. I then get the image that is being used and create a bitmap with it. I then get the image and create a new bitmap, then add that to the canvas. The canvas is then used for the ondraw. The coordinates are found by getting the width of the photoview and x off the photontap and then just doing x*width, then doing the same for y and then invalidate it. I have added the code below.

    drawHandler.setOnPhotoTapListener(new OnPhotoTapListener() {
        @Override
        public void onPhotoTap(ImageView view, float x, float y) {
            onTap( x* width, y*height);
        }
    });
}

public void onTap(float x, float y){
    oldy = currenty;
    oldx = currentx;

    currenty = y;
    currentx = x;
    if(oldy!=null && oldx!=null) {
        if(oldx!= x && oldy!=y) {
            drawHandler.x = x;
            drawHandler.y = y;
            drawHandler.oldX = oldx;
            drawHandler.oldY = oldy;
            drawHandler.draw(canvas);
            drawHandler.invalidate();
        }
    }

}

This is within the DrawHandler

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
        Log.d("Draw Method Accessed", "About to draw");
        canvas.drawLine(x, y, oldX, oldY, black);

    }
}

I dont know why it isn't drawing the line

Darren
  • 75
  • 6
  • ok, and your question is ...? – pskink Dec 08 '17 at 17:49
  • It doesnt appear, it goes to the method and doesnt show the line – Darren Dec 08 '17 at 18:02
  • what actually do you want to achieve? – pskink Dec 08 '17 at 18:02
  • To draw a line from the old tap location to the new tap location – Darren Dec 08 '17 at 18:05
  • so override `onDraw` - no need for a `Bitmap` and such things - simply call `Canvas#drawLine` – pskink Dec 08 '17 at 18:07
  • I did in the DrawHandler, I have added it in the main question. The bitmap is for the canvas,. – Darren Dec 08 '17 at 18:11
  • no, i mean do all the stuff inside `View#onDraw` method and use `View`'s `Canvas`, like [this](https://pastebin.com/raw/DsahtVTW) – pskink Dec 08 '17 at 19:06
  • @pskink sorry for the late reply, no it didnt this is what i did https://pastebin.com/AqmSvZ9p and then just initalised it and tried to create a new ontap – Darren Dec 08 '17 at 20:37
  • Most of the features, i cant zoom in now or create the line as well. I think it could be how i done the code though. Here is how i used it. https://pastebin.com/ehnAXQaK – Darren Dec 08 '17 at 20:46
  • also i should say the ontap i tried not referencing anything and it still didnt work – Darren Dec 08 '17 at 20:47
  • what did not work in my code? does it show lines when you tap? does it scale when you zoom? this is what you want, dont you? – pskink Dec 08 '17 at 20:48
  • It doesn't enter the ontap if going off the log.i, it doesnt zoom either – Darren Dec 08 '17 at 20:51
  • what does not zoom? did you try my code _without_ any modifications? just copy/paste and use `setContentView(new PV(this))` in your `Activity#onCreate` method - then tap 3 or 4 times and you will see the connecting lines - after that you can doubleclick to zoom in/zoom out and the lines should be resized too – pskink Dec 08 '17 at 20:52
  • getDisplayMatrix needs a matrix, which one should i put into it on line with path.transform – Darren Dec 08 '17 at 21:03
  • https://gyazo.com/2fc8dd44870de570c78b747db92257a9 thats the error also i had to change the implements to implements OnPhotoTapListener because it doesnt work and just produces a error (sorry for gyazo because its on linux) also thank you for helping :) – Darren Dec 08 '17 at 21:11
  • ok i have old version `com.github.chrisbanes.photoview:library:1.2.4` - in new version it needs a `Matrix` - just create field `Matrix m = new Matrix()` and pass it to `getDisplayMatrix` method – pskink Dec 08 '17 at 21:13
  • https://gyazo.com/ca93ce5c718537cb63ecf5473e7067ba turns void type not allowed – Darren Dec 08 '17 at 21:24
  • just get `com.github.chrisbanes.photoview:library:1.2.4` and check what `getDisplayMatrix()` returns - simply change your `build.gradle` for a while – pskink Dec 08 '17 at 21:28
  • It works, thank you for being so patient. Please make it as answer and i will mark it as the answer :) – Darren Dec 09 '17 at 00:55

0 Answers0