简体   繁体   English

java applet是否有可能将applet转换为png文件

[英]java applet is it possible to make an applet into png file

Hi im new to programming and im starting to program with java im creating a program that will paint in the applet and everything seems good. 嗨,我是编程新手,我开始用java编程,我创建了一个将在applet中绘制的程序,一切似乎都很好。

The thing is i want to save the paint that i have done and i was wondering it is possible to convert that applet or the paint method to png file. 问题是我想保存自己做过的绘画,我想知道是否可以将小程序或绘画方法转换为png文件。 If not i was working on that everytime the user paint it will save the coordinates, color and size and save it in txt then i have to create a reader or a display for it. 如果不是这样,我每次用户绘制时都会保存坐标,颜色和大小并将其保存为txt,那么我必须为其创建阅读器或显示器。

Is it possible to make an applet to png file ? 是否可以将小程序转换为png文件?

You can convert an image into a png file by using ImageIO.write(...) . 您可以使用ImageIO.write(...)图像转换为png文件。 Hopefully it should be fairly easy to extract the image from your painting, but this depends on much that has not yet been shown to us. 希望从您的绘画中提取图像应该相当容易,但这取决于很多尚未显示给我们的东西。 Please show us your pertinent code so that I can improve this answer with concrete code. 请向我们展示您的相关代码,以便我可以通过具体代码来改善此答案。

Assuming that you're drawing within a JPanel's paintComponent method or an Applet's paint method, then you can instead paint into a BufferedImage, and then use that Image to convert to your png file. 假设您正在使用JPanel的paintComponent方法或Applet的paint方法进行绘制,则可以改为绘制为BufferedImage,然后使用该Image转换为png文件。

The other issue is writing from the applet itself to the file on the disk, and there may be permission issues with this. 另一个问题是从applet本身写入磁盘上的文件,并且可能存在权限问题。 Myself, I avoid programming applets like the plague, since they're really not used much any more, and in fact some browsers don't allow use of them. 我本人避免编写像瘟疫这样的小程序,因为它们实际上已经不再使用了,实际上,某些浏览器不允许使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM