title: Java applet - saving an image in a png format
body: <p>I am creating a simple applet for avatar-making. You can choose face, hair, eyes, etc and then save it to a disc as a png file. The simple version (without the interface for the simplicity purpose) looks like this:</p>
  
  <pre><code>import java.awt.*;
  import java.applet.*;
  import java.net.*;
  
  public class Example extends Applet
   {
  
   Image my_gif;
   Image my_gif2;
   URL base;
   MediaTracker mt;
  
   public void init() 
   {
          mt = new MediaTracker(this);
       try {
               base = getDocumentBase();
       }
       catch (Exception e) {}
  
         my_gif = getImage(base,"1.gif");
         my_gif2 = getImage(base,"2.gif");
  
         mt.addImage(my_gif,1);
         mt.addImage(my_gif2,2);
  
        try {
             mt.waitForAll();
        }
        catch (InterruptedException  e) {}
    }
   public void paint(Graphics g) 
   {
         g.drawImage(my_gif,0,0,this);
       g.drawImage(my_gif2,0,0,this);
   }
   }
  </code></pre>
  
  <p>This example consists of two files. When run they are visible in a correct way. Now I would like to save it to a disc - I can save one image using BufferedImage but I want to "flatten" two or more images and save it. Any help would be greatly appreciated. I also agree that perhaps my approach is not the right one and would be grateful for any corrections.</p>