Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find out the scale of an graphics matrix in Android

Tags:

So, it appears to be fairly easy to do pinch zoom in android - but I would also like to be able to snap back the image when it goes out of bounds, and to do that the most reasonable thing seems to be to do things like when the scale < 1, rescale to 1. However, I can't seem to find a good way to retrieve the scale from the the graphics matrix.

One possible solution might be to map a point using the matrix's mapPoints function and see where it ends up, but in addition to being trickly, that just feels ugly and indirect to me. Are there any better solutions for retrieving the scale from an Android graphics matrix?

like image 291
OverclockedTim Avatar asked Mar 04 '11 19:03

OverclockedTim


People also ask

What is matrix in Android?

Just think of a matrix as an array of numbers. In this case, an Android Matrix has 3 rows of 3 numbers. Each number tells an Android graphics function what to do to scale (bigger/smaller), translate (move), rotate (turn) or skew (distort in a 2D plane) the "thing" which the matrix is applied to.

What is scaling in Android Studio?

A class that defines a quantity by which a number should be multiplied when formatting. To create a Multiplier, use one of the factory methods. See also: NumberFormatter.


1 Answers

float[] f = new float[9];
matrix.getValues(f);

float scaleX = f[Matrix.MSCALE_X];
float scaleY = f[Matrix.MSCALE_Y];

will probably be what you are looking for. the values given will be as followed:

0 : Scale X

1 : Skew X

2 : Translate X

3 : Scale Y

4 : Skew Y

5 : Translate Y

6 : Perspective 0

7 : Perspective 1

8 : Perspective 2

like image 165
Henrik Avatar answered Oct 12 '22 12:10

Henrik