我正在尝试缩放/翻译 java.awt。Shape with 仿射变换为了将其绘制在定义的边界矩形中。
此外,我想在具有 ' 的绘图区域中绘制它zoom' 范围。
我尝试了 AffineTransform 的各种串联,但找不到正确的序列。例如,以下解决方案是错误的:
double zoom=(...);/* current zoom */
Rectangle2D viewRect=(...)/** the rectangle where we want to paint the shape */
Shape shape=(...)/* the original shape that should fit in the rectangle viewRect */
Rectangle2D bounds=shape.getBounds2D();
double ratioW=(viewRect.getWidth()/bounds.getWidth());
double ratioH=(viewRect.getHeight()/bounds.getHeight());
AffineTransform transforms[]=
{
AffineTransform.getScaleInstance(zoom, zoom),
AffineTransform.getTranslateInstance(-bounds.getX(),-bounds.getY()),
AffineTransform.getTranslateInstance(viewRect.getX(),viewRect.getY()),
AffineTransform.getScaleInstance(ratioW, ratioH)
};
AffineTransform tr=new AffineTransform();
for(int i=0;i< transforms.length;++i)
{
tr.concatenate(transforms[i]);
}
Shape shape2=tr.createTransformedShape(shape);
graphics2D.draw(shape2);
关于正确的 AffineTransform 有什么想法吗?
非常感谢
Pierre
注意AffineTransform http://download.oracle.com/javase/6/docs/api/java/awt/geom/AffineTransform.html转换“以最常用的方式”连接起来,这可以被视为last in, 先出命令。效果可以看这个example http://sites.google.com/site/drjohnbmatthews/point-in-polygon。给定以下序列,得到的结果Shape
首先旋转,然后缩放,最后平移。
at.translate(SIZE/2, SIZE/2);
at.scale(60, 60);
at.rotate(Math.PI/4);
return at.createTransformedShape(...);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)