Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android画布中调整路径大小_Java_Android_Android Canvas - Fatal编程技术网

Java 在android画布中调整路径大小

Java 在android画布中调整路径大小,java,android,android-canvas,Java,Android,Android Canvas,我在画布上画了一条路。单击一次,我想调整路径的大小。比如说我想把它改成原来的两倍 我试过了,但它在画布上把路径转移到了另一个位置。这是我用的代码 Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(100,0); p.transform(translateMatrix); 如何在android中调整路径大小?我自己还没有这样做,但您可能应该使用 Matrix scaleMatrix = new Matrix(

我在画布上画了一条路。单击一次,我想调整路径的大小。比如说我想把它改成原来的两倍

我试过了,但它在画布上把路径转移到了另一个位置。这是我用的代码

Matrix translateMatrix = new Matrix();
translateMatrix.setTranslate(100,0);
p.transform(translateMatrix); 

如何在android中调整路径大小?

我自己还没有这样做,但您可能应该使用

Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(sx,sy, px, py);
p.transform(scaleMatrix); 
其中
sx,sy
在您的情况下应该是
2,2
,如果您想要两倍的尺寸
在你的情况下,
px,py
可能应该是
0.5,0.5

我已经尝试了smitalm提供的解决方案。但这条路仍在改变它的位置。我试过这种方法,它对我有效

Matrix scaleMatrix = new Matrix();
RectF rectF = new RectF();
path.computeBounds(rectF, true);
scaleMatrix.setScale(1.25f, 1.25f,rectF.centerX(),rectF.centerY());
path.transform(scaleMatrix); 
Bound.centerx和center Y将帮助您将路径缩放到其中心位置,scale_pathSX和scale_pathSY表示您要缩放路径的大小, 大规模
缩放路径X和缩放路径SY=1.001;对于小比例路径x和比例路径sy=0.999

谢谢你的回复。我试过你的密码。它在缩放,但同时也改变了位置。我想把它放在中间。我该怎么做?@Zach然后你必须使用允许枢轴的setScale版本,见编辑后的答案。rectF.centerX()和rectF.centerY()将帮助你缩放路径w.r.t其中心位置,1.25f,1.25f是(x和y轴缩放),PS:对于缩放大(x,y轴)=1.001;对于小刻度(x,y轴)=0.999;
RectF bounds = new RectF();
path.computeBounds(bounds, true);
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(scale_pathSX, scale_pathSY,
    bounds.centerX(),bounds.centerY());
path.transform(scaleMatrix);