开发者

Android imageview matrix operations

开发者 https://www.devze.com 2023-02-06 15:22 出处:网络
Me used imageview to display i开发者_如何转开发mage. I set the scale type as ScaleType.MATRIX There is option for scaling (zooming), dragging and all. All this are done by doing matrix manipulations

Me used imageview to display i开发者_如何转开发mage.

I set the scale type as ScaleType.MATRIX

There is option for scaling (zooming), dragging and all. All this are done by doing matrix manipulations mainly postTranslate and postScale

My problem now it can be drag such that the image is not in the screen

So how we get how much it is dragged.

In brief

I have two matrix (android.graphics.Matrix) one the initial stage and the other that i got after drag and zoom. Now from this 2 matrices i want to calculate how much it moved in x-direction and y-direction?

What matrix operation i need to do here.

Thank you


You can get float array of matrix's values using getValues function. The 2nd (Matrix.MTRANS_X) and 5th (Matrix.MTRANS_Y) values of matrix are transitions in x and y directions.

http://developer.android.com/reference/android/graphics/Matrix.html


You need to apply the matrix to get the transformed coordiantes. Matrix class has a few methods that will give you tranformed coordinates.

Look at

  • mapPoints
  • mapVectors
  • mapRect

Once you have the points (original and the transformed) you can easily calculate the distance using euclidean distance.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号