2013-09-05 27 views
5

我在畫布中繪製了一條路徑。單擊我想調整路徑大小。假設我想將它的尺寸加倍。在Android畫布中調整路徑大小

我試過path.transform,但它將路徑轉移到了不同​​的位置。這是我用的代碼

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

如何在android中調整路徑大小?

回答

16

我嘗試過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); 
5

還沒有我自己做到了這一點,但你可能應該使用

Matrix scaleMatrix = new Matrix(); 
scaleMatrix.setScale(sx,sy, px, py); 
p.transform(scaleMatrix); 

其中sx,sy應該是2,2你的情況,如果你想雙大 和px,py大概應該是0.5,0.5你的情況

+0

感謝您的回覆。我試過你的代碼。它在擴大規模,但同時也在改變其立場。我想在中心調整它。我怎樣才能做到這一點? – Zach

+0

@Zach然後你必須使用允許樞軸的setScale版本,參見編輯答案。 – hendrix