GIF

  • Java handles GIF well, somewhat less well JPG
  • Transparency images work fine (use Transparency on Powermacs to convert standard to 89a GIF)
  • getting an image in an applet is fairly straight forward as long as you can wait for it to load

    	public void init(){
    		img = getImage(getDocumentBase(),"my.gif");
    	}
    	
    	public void paint(Graphics g){
    		g.drawImage("my.gif",0,0,this);
    	}
    
    That should draw the image in your applet window.
    
  • You can clip the image to a given rectangle when you draw it:

    	public void paint(Graphics g){
    		g.clipRect(10,10,10,10);
    		g.drawImage("my.gif",0,0,this);
    	}
    
    This could be useful for drawing parts of an image in various places. Eg.

    	public void paint(Graphics g){
    		g.clipRect(10,10,10,10);
    		g.drawImage("my.gif",0,0,this);
    		g = getGraphics(); //reset clipRect
    		g.clipRect(20,20,10,10);
    		g.drawImage("my.gif",10,10,this);
    	}
    This would draw the same sub-image in two places.
    

  • Here's another example of using drawImage action, and the source code. (It uses the file "group.gif" which is 15-icons wide).

    Assignment

  • Try to combine image and sound examples (apr17.html and this page)
  • Don't forget to use the links, especially the HowDoI? page, which can be quite helpful.