将图像保存到 Applet 中的文件?
所以这就是事情,我试图为一个网页游戏做一个Applet来产生自定义"头像,这个头像是为一个国家的军队提供的,所以头像的选择取决于形象用户,图片上的边框也代表该用户所属的四边形.
So here is te thing, Im trying to do an Applet for a webgame to produces "custom" avatars, this avatar are for a kind off an army of a country, so the avatar cosnsit on the image of the choice of the user, and a frame on the picture thtat represent the quad that the user belongs too.
所以我的计划是让他们从他们计算机中的一个文件中进行选择,然后他们选择他们所属的小队.在此之后,他们将看到图片的预览,他们可以将其保存到他们的计算机中,以便以后在游戏中使用.
So my plan is to make them choose from a file from their computer, and then they choose the squd that they belong to. After this they will see a preview of the picutre and they can save it to their computer to later use it on the game.
我知道您可以在组件的背景上使用 Graphic 或 Graphic2D 绘制图像,但是当我想将其保存到文件时,我该怎么做?
I know that you can draw image with a Graphic or Graphic2D on the background of a component, but then when I want to save it to a file, How I do that?
推荐答案
使用 Plug-In 2 (PI2 - 1.6.0_10+) 架构 JRE 部署的小程序不需要数字代码签名.在 PI2 JRE 中,嵌入式小程序可以访问通常仅适用于 Java Web Start 应用程序的所有服务.
Digital code signing is not required for an applet deployed using a Plug-In 2 (PI2 - 1.6.0_10+) architecture JRE. In a PI2 JRE, an embedded applet can access all the services normally only available to Java Web Start apps.
此小程序感兴趣的服务是 FileOpenService (FOS),以及PersistenceService (PS).FOS 可用于允许用户导航到文件(或者更确切地说 - 文件内容)对象并从中获取流.一旦用户对裁剪后的图像感到满意,将其保存到 PS 以供以后检索(使用 ImageIO,如前所述).
The services of interest to this applet would be the FileOpenService (FOS), and the PersistenceService (PS). The FOS could be used to allow the user to navigate to a File (or rather - a FileContents) object and obtain streams from it. Once the user is happy with the cropped image, save in to the PS for later retrieval (using ImageIO, as already mentioned).
相关文章