【发布时间】: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