Get Canvas coordinates after scaling up/down or dragging in android

前端 未结 2 1391
终归单人心
终归单人心 2020-12-02 13:40

I\'m developing an application in which I\'m pasting images, doing drawing and painting on canvas. This app can also Scale up/down the canvas or drag it to different locatio

2条回答
  •  攒了一身酷
    2020-12-02 14:07

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        clipBounds_canvas = canvas.getClipBounds();
        /////Do whatever you want to do..!!!            
    };
    
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        int x = ev.getX() / zoomFactor + clipBounds_canvas.left;
        int y = ev.getY() / zoomFactor + clipBounds_canvas.top;
        //Use the above two values insted of ev.getX() and ev.getY();
    }
    

    Hope this will help.

提交回复
热议问题