【问题标题】:why move position that i use affine transform in java 1.6se为什么移动我在 java 1.6se 中使用仿射变换的位置
【发布时间】:2012-12-06 21:16:10
【问题描述】:

我想缩放形状。

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

那么,不仅shape的长度是trans,而且shape的起点也会移动

为什么?

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 : resize

x,y 是鼠标坐标

【问题讨论】:

  • 因为这就是缩放的作用。如果您希望保留起点,则还需要翻译。

标签: java affinetransform


【解决方案1】:

您必须对 AffineTransform 对象应用操作。在您的情况下,您想要扩展:

af.scale(xratio, 1);

这个想法是将当前矩阵与表示比例的矩阵相乘。这就是组合变换的工作原理:通过矩阵相乘(注意!相乘的顺序很重要,矩阵相乘时 A*B != B*A 也很重要)。

这不是清除整个矩阵并在矩阵的默认线性缩放模板之后插入缩放值。

【讨论】:

    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2010-12-17
    • 1970-01-01
    相关资源
    最近更新 更多