无法获取我的坐标graphics2D mouseclick Java [英] can't get my coordinates graphics2D mouseclick java

查看:97
本文介绍了无法获取我的坐标graphics2D mouseclick Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了扩展的JLabel类,在其中使用下面的代码绘制地图: new AffineTransform()是要保留我的图片的身份,原为(0,0,w,h)

I got an extended JLabel class where I draw my Map using the code below : the new AffineTransform() is the identity to left my image as it is (0,0,w,h)

 mygraphics2D = (Graphics2D) getGraphics();
 graphics2D.scale(2.0,2.0) ;
 graphics2D.rotate(....
 graphics2D.drawImage(myImageIcon.getImage(),new AffineTransform(), this);

现在,当我使用此事件单击JLabel时:

now when I click on my JLabel using this event :

public void mouseClicked(MouseEvent e) {
x =e.getX() ;
y = e.getY();
NewX = ????
NewY = ????
}

我想检索我尝试过的新坐标缩放,旋转的...坐标"

I want to retrieve my new coordinates "the scaled,rotated ... coords" I tried

Point2D ptSrc = new Point2D.Double(x, y);
Point2D ptDst = new Point2D.Double(0, 0);
mygraphics2D.getTransform().transform(ptSrc, ptDst);

但是ptDst与(缩放,旋转,..)坐标不同,请提供任何帮助!

but the ptDst is different from the (scaled,rotated,..) coordinates, any help please !!!

推荐答案

听起来您需要同时进行正向和逆向转换才能在两个坐标系之间进行转换.在此示例中,缩放方程式是明确的;在这种替代方法中,使用了第二个AffineTransform.

It sounds like you need both a forward and inverse transform to translate between the two co-ordinate systems. In this example, the scaling equations are explicit; in this alternate approach, a second AffineTransform is used.

这篇关于无法获取我的坐标graphics2D mouseclick Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆