制作绘图应用程序的屏幕截图 +绘制二维形状的轮廓
我正在制作一个绘图程序,通过将图形 2D 对象(即线条、矩形和椭圆形)放置在面板上来使用它们。考虑到这一点,我有两个问题:
1)如何将当前在面板上描绘的图像作为 PNG、JPG 或类似文件存储到磁盘上?
2)我添加了拖动功能。如何实现一个功能,以便在将矩形、直线或椭圆形实际放置到画布上之前可以看到矩形、直线或椭圆形的“轮廓”(但在释放鼠标按钮后不将轮廓放置在画布上)?我看不到任何 MouseListener 方法可以做这样的事情。
I am making a drawing program, using the Graphics 2D objects (lines, rectangles and ovals, namely) by placing them on a panel. With that in mind, I have 2 questions:
1) How can I store the images currently portrayed on the panel as PNG, JPG or similar file onto disk?
2) I have added a drag function. How can I implement a function so that one can see the "outline" of the rectangle, line or oval, before it is actually put onto the canvas (but not placing the outline on the canvas after the mouse button has been released)? I can't see that any of the MouseListener methods can do such a thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建 BufferedImage 并在其上绘制任何组件。 屏幕图像 类可以为您完成此操作。
You can create a BufferedImage and paint any component onto it. The Screen Image class does this for you.
在此示例中,可以拖动形状本身,而不是其轮廓,但是
Node
类的draw()
方法可以根据需要进行修改。矩形轮廓用于选择,就像在桌面上一样。In this example, the shape itself may be dragged, rather than its outline, but the
draw()
method of classNode
may be modified as desired. A rectangular outline is used for selection, as on a desktop.1)图像IO
http://www.java-tips.org/java-se-tips/javax.imageio/how-to-save-a-bufferedimage-to-a-png-file.html
2 )想不出2的答案。
1) ImageIO
http://www.java-tips.org/java-se-tips/javax.imageio/how-to-save-a-bufferedimage-to-a-png-file.html
2) Can't think of an answer for 2.