2012-12-06 15 views
0

我想缩放形状。为什么移动我在java中使用仿射变换的位置1.6se

所以我在仿射变换中使用setToScale方法。

那么,不仅形状的长度为反式,而且形状的出发点移动

为什么?

public void initResize(int x, int y) { 
    oldX = x; 
    oldY = y; 
} 

public void resize(int x, int y) { 
    double xratio = (double)(x - shape.getBounds().x)/(shape.getBounds().width); 
    double yratio = (double)(y - shape.getBounds().y)/(shape.getBounds().height); 

    af.setToScale(xratio, 1); 
    shape = af.createTransformedShape(shape); 
    anchor.resize(shape.getBounds()); 

    oldX = x; 
    oldY = y; 
} 

方法调用的顺序是MousePress:initResize,MouseDrgged:调整

的x,y是鼠标的坐标

+2

因为这就是缩放比例。如果你想保留起点,你也需要翻译。 –

回答

0

你必须在AffineTransform对象上应用的操作。在你的情况下,你想要缩放:

af.scale(xratio, 1); 

这个想法是,你将当前矩阵乘以代表比例的矩阵。这就是组合变换的工作方式:乘以矩阵(注意!乘法的次序很重要,当矩阵相乘时也是A * B!= B * A)。

这不是清除整个矩阵,而是按照矩阵的默认线性比例模板插入比例值。