im having a single Bitmap in a surfaceview. I am using multi touch to handle gestures such as zoom and drag, the problem is that when i scale the bitmap i dont want it to be able to be down scaled that much it wont cover the whole display(surface view). I have found no way to work around this since i cant find a way to get the current downscaled bitmaps current height or width.
Here's some of my code:
private void multiTouchBehavior(MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN)
{
_oldDist = spacing(event);
if(_oldDist > 10f) // just be secure of a bug in the API
{
_saved.set(_matrix);
_mid = midPoint(event);
}
}
else if(event.getAction() == MotionEvent.ACTION_MOVE)
{
_newDist = spacing(event);
if(_newDist > 10f)
{
_matrix.set(_saved);
float scale = _newDist / _oldDist;
_matrix.postScale(scale, scale, _mid.x, _mid.y);
}
}
}
And here is what happens in method spacing(event) :
private float spacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
My onDraw(canvas) is just canvas.drawBitmap(myBitmap, _matrix, null)
Anyone know how i could solve this problem?
So just to make sure you get my problem right think of it as a big map of the world that i want to able to zoom in to, and of course zoom out on when iv'e already zoomed in, but NOT allowing it to be out zoomed more than it is at start.
Found my solution, there probably is a better way but now I use:
matrix.mapRadius(1);
that i can compare to a variable initialized to that method-value in beggining.
Edit:
float[] f = new float[9];
matrix.getValues(f);
float xScale = f[0];
float yScale = f[3];
works better and is easier tho.