1

Let's assume I have some pin view which I want to render on top of PhotoView according current scale and zoom (aka simplified TileView).

PhotoView provide method setOnMatrixChangeListener when we zoom or scroll image it will trigger with displayed matrix parameter which is represented as RectF type.

So my question is how properly calculate positioning and scale of pin view on top of PhotoView depending on current zoom and scroll?

photView.setOnMatrixChangeListener(object: OnMatrixChangedListener {
   override fun onMatrixChanged(rect: RectF?) {
    // calculation of new coordinates and scale here
     ...
    pinView.x = calculatedCoordinateX;
    pinView.y = calculatedCoordinateY;
    pinView.scale = calculatedScale;
   }
}) 

Any material to study how to use such matrix for such calculation, positioning and scale?

Appreciate if anyone can provide sample code how exactly to solve such problem.

Jayson Minard
  • 84,842
  • 38
  • 184
  • 227
Arsenius
  • 4,972
  • 4
  • 26
  • 39
  • 1
    read carefully `android.graphics.Matrix` API documentation - there are several `map*()` methods – pskink Feb 18 '18 at 09:25
  • @pskink thanks, it could be nice if you also could provide some example code with explanation – Arsenius Feb 18 '18 at 09:28
  • 1
    simply use current display matrix: [getDisplayMatrix()](https://github.com/chrisbanes/PhotoView/blob/master/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java#L167) and try to play with `Matrix#map*()` methods – pskink Feb 18 '18 at 09:30
  • 1
    for example make a custom `PhotoView` and override its `onDraw` method - call `super.onDraw` and then get current display matrix, call `mapPoints` on float array `float[] pts = {200, 400}` and then call `canvas.drawCircle(pts[0], pts[1], 100, paint)` and see where circle is drawn – pskink Feb 18 '18 at 09:51
  • @pskink Thank you for your answer I will experiment in the next few days with it. Yes I got your point. – Arsenius Feb 18 '18 at 15:48
  • 1
    run [this](https://pastebin.com/U7NHCFJs) sample code, zoom in, scroll a bit and watch two red little dots – pskink Feb 18 '18 at 15:54
  • @pskink this code doesn't include scale calculation on current zoom factor. Because the dot should become bigger when we zoom in and smaller when we zoom out. Anyway appreciate your effort to help me out with this problem. – Arsenius Feb 19 '18 at 02:34
  • 1
    simply replace `20` with "mapped radius" in `canvas.drawCircle(mappedX, mappedY, 20, paint)` – pskink Feb 19 '18 at 03:34

0 Answers0