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.
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?
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.
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).
here is the notepad code where u can save the contents and also if u convert the text into an image.so try going through it
Use
JFileChooser#showSaveDialog()
to ask user to select/specify a file to save and then useImageIO#write()
to write theBufferedImage
to the file.The applet needs however to be signed to avoid the enduser being scared by security warnings.
I think I'd be inclined to interact the Java with Javascript on the same page, and give an 'export' button which serialises it to PNG locally, and offers it as a download (should be possible all without the user needing to refresh the page or mess around). There are some interesting comments in this previous question: Java applet - saving an image in a png format
The notepad program which i have posted just above this post gives the load image of any type and also to save image of any type....
so you cab refer the same code to load the image and save the image