如何在Java中获得缩放Shape的新高度

时间:2011-06-20 20:27:36

标签: java shape affinetransform

我正在为特定点缩放形状,如下所示:

                AffineTransform t = shape.getAffineTransform();

                AffineTransform translatAffine =AffineTransform.getTranslateInstance(-cx, -cy);
                AffineTransform scaleAffine= AffineTransform.getScaleInstance(sx,sy);
                scaleAffine.concatenate(translatAffine); 
                translatAffine = scaleAffine;

                scaleAffine =AffineTransform.getTranslateInstance(cx, cy);
                scaleAffine.concatenate(translatAffine);
                translatAffine = scaleAffine;                   

                scaleAffine= new AffineTransform(t);
                translatAffine.concatenate(scaleAffine); 
                shape.setAffineTransform(translatAffine);

当我尝试使用shape.getHeight()获得新高度时,我得到初始高度

1 个答案:

答案 0 :(得分:0)

通过获取affineTransform并计算新的高度,我找到了一个工作。我在上面的代码中添加了以下代码

System.out.println("The new height :"+ shape.getHeight() *  shape.getAffineTransform().getScaleX());