画布缩放前进到到点(0,0) [英] Canvas Zoom goes to point (0,0)

查看:101
本文介绍了画布缩放前进到到点(0,0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在缩放画布的一个问题。我做了一个自定义的视图中,我在画关系图现在,当我缩小在去的位置(0,0)在画布上。我看到不同的线程和问题,但找不到合适的答案。

I am having a problem in zooming the canvas. I have made a customized view in which I am drawing relationship diagrams now when I zoom out the canvas in goes to the position (0,0). I have seen different threads and questions but could not find appropriate answer.

我在做什么的方法的onDraw的。

What i am doing in onDraw Method is.

  canvas.scale(mScaleFactor, mScaleFactor);

我也看到了canvas.scale(X,Y,PX,PY)方法,但我不知道如何让x和y轴点。

I have also seen the canvas.scale(x, y, px, py) method but i do not know how to get the pivot points of x and y.

public boolean onScale(ScaleGestureDetector detector) {

mScaleFactor *= detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.4f, Math.min(mScaleFactor, 5.0f));
if(mScaleFactor>=1)
   mScaleFactor=1f; 

invalidate();
return true;

}

推荐答案

该枢轴点基本上就是你的画布,将围绕转变了点,用0,0枢轴所以使得扩展其面向这一点缩水。
使用下面的方法可以改变支点,无论你想要的:

The pivot points are basically the point that your canvas will be transformed around, so scaling with a pivot of 0,0 makes it shrink towards that point. using the following method you can change the pivot point to wherever you want it:

canvas.scale(x, y, px, py);

现在新的东西:
如果你希望你的画布朝其中心进行缩放,你只需要知道在画布中间的点:

Now for the new stuff: If you want your canvas to be scaled towards its centre, you will just have to know the point in the middle of your canvas:

float cX = canvas.getWidth()/2.0f; //Width/2 gives the horizontal centre
float cY = canvas.getHeight()/2.0f; //Height/2 gives the vertical centre

然后你就可以使用这些坐标缩放:

And then you can scale it using those coordinates:

canvas.scale(x, y, cX, cY);

这篇关于画布缩放前进到到点(0,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆