Zoom a plot with two fingers using grafica library

edited March 13 in Android Mode

Could you please provide me an example code in processing i3 that i can make zoom with two fingers in my App,in Android Mode??I would like to zoom in the whole screen, not only in a shape..


  • edited March 13

    I tried to use the method void onPinch() like:

          void onPinch(float x, float y, float d)                
                  rectSize = constrain(rectSize+d, 10, height);
                  println("PINCH:" + x + "," + y + "," + d);

    but i cant find what i might put instead of rextSize to zoom the whole app, whole screen.

  • edited March 13


    i dont know with only processing but using android apis you can do that very quickly; guidelines:

    • you import onTouchListener && import android.view.MotionEvent && import android.graphics.Matrix;

    • you add your listener to some object (let us say your imageView) and its initial matrix (which is 1): myImage.setScaleType(ScaleType.MATRIX);

    • you create on touch() method; it returns the touch event and transmits it to the main method: onTouchEvent(MotionEvent event)

    • in this method you count the pointers (event.getPointersCount()) and get the coordinates x && y for them with event.getX, event;getY() or event getRawX() && event getRawY(); so you have 4 values (if two pointers: you can add here some restriction in order to eliminate the case that two pointers are very very near: they are 2 if(....)

    • now you can calculate the (euclidian) distance between the points and according to it you have to scale the bitmap to the new matrix: which can be greater (1.5....10.....) or smaller (0.1, 0.5........) ; dont forget to center the matrix on the midpoint of the bitmap.

    • finally you have to add a timer in order to get rid of the old values (from getX()...)

    that's done!

    more details: https://developer.android.com/reference/android/view/View.OnTouchListener.html

    PS: you can also use the onScaleGestureDetector API: https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener.html

  • I am using grafica library to make plots..Maybe is there special functions for zooming the graph??

  • I know that in Java Mode i can zoom the graph with the function plot.activateZooming() but when i turn into Andoid Mode doesn't worked.

Sign In or Register to comment.