我们可以放大缩小在画布上绘制的图形吗?
我们有一个旧的(超过 10 年历史)Java Swing 应用程序,它根据实验室数据在 JCanvas(JComponent 的子类)上绘制大量圆圈以及这些圆圈之间的连接(线)。
由于数据越来越大,我们现在无法显示整个绘图。我们已将 JCavans 放入 JScrollPane 中,但滚动绘图不方便。
我们可以为其添加放大缩小吗?如果是,怎么办?我知道我们可以缩放图像,但是 Canvas 上的绘图是图像吗?
谢谢,
编辑:
我们在 paintComponent(Graphics g)
方法中绘制这些圆圈并使用 Graphics 绘制线条。
We have an old (more than 10yrs old) Java Swing applicatin which draws lots of circles and connections (lines) between those circles on a JCanvas (a subclass of JComponent) based on lab data.
Because the data becames bigger and bigger, we cannot display the entire drawing now. We have put the JCavans into a JScrollPane but it is not convenience to scroll the drawing.
Can we add zoom in zoom out for it? if yes, how? I know we can zoom image but the drawing on Canvas is an image?
thanks,
EDIT:
we draw those circles and line with Graphics within paintComponent(Graphics g)
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对传递给
paintComponent
方法的Graphics2D
对象应用缩放Transform
。您可以在 Java 2D 编程教程中了解如何使用它。You could apply a scaling
Transform
to theGraphics2D
object passed to thepaintComponent
method. You can learn how to use it in the Java 2D programming trail.如果不了解有关您的应用程序的任何信息,就很难提供有用的建议(添加代码片段或更好的精简示例应用程序将有助于展示事物的绘制方式),但我会尝试一下:
为什么不呢?在绘制每个圆/线之前,将 x、y 和宽度、高度值乘以比例因子?我假设您的画布在某个地方使用
Graphics
对象来绘制每个形状?Without knowing anything about your application it's hard to provide useful advice (adding a code snippet or better yet a cutdown example app would be helpful to show how things are being drawn), but I'll give it a shot:
Why don't you multiply the x,y and width,height values by a scaling factor before you draw each circle/line? I assume that somewhere your canvas is using a
Graphics
object to draw each shape?