JComponent JPanel缩放,平移和坐标问题 [英] JComponent JPanel Zoom, pan and Coordinates Question

查看:160
本文介绍了JComponent JPanel缩放,平移和坐标问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JPanel ,其中包含一个用户可以缩放和平移的矢量图像。覆盖此图像是(透明) JComponent ,我允许用户注释底层图像。这在全尺寸下工作得很好,但如果我使用 AffineTransform 放大,则叠加坐标也会受到影响。因此,如果用户在图像上绘制一个框,则该框也会缩放。

I have a JPanel with an vector image that the user can zoom and pan on. Overlaying this image is a (transparent) JComponent, which I allow the user to annotate the underlying image. This works great at full scale, but If I zoom in, using AffineTransform, the overlaying coordinates are affected also. So, If a user draws a box on the image the box is scaled also.

有关如何解除此行为的任何建议吗?因此 JComponent 不受 JPanel AffineTransform

Any suggestions on how to decouple this behaviour? So that the JComponent is not affected by the JPanel's AffineTransform?

推荐答案

通常,您需要前向和反向变换才能在两个坐标系之间进行转换。在此示例中,缩放方程式是明确的;在此备用方法中,使用了第二个 AffineTransform

Typically, 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.

这篇关于JComponent JPanel缩放,平移和坐标问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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