Hey Warren,
There is a good discussion of this in the book
Java 2D Graphics from O'Reilly. I think I can give you the gist of it:
// you have to import JPEG support along
// with the usual suspects
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.io.*
// image reference
private BufferedImage myImage;
// a method to import a certain JPEG image
// might look like this
private void loadArrowImage(){
try
{
String filename = "MyPicture.jpg";
FileInputStream in = new FileInputStream( filename );
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( in );
myImage = decoder.decodeAsBufferedImage();
in.close();
}
catch( ImageFormatException ife )
{
System.out.println("Image source file invalid.");
}
catch( FileNotFoundException fnfe )
{
System.out.println("Could not locate image file.");
}
catch( IOException ioe )
{
System.out.println("Error reading image file.");
}
}
// you display it by passing it to the graphics object
public void paint(Graphics g) {
// cast to Graphics2D object
Graphics2D g2 = (Graphics2D)g;
// call a drawImage method
g2.drawImage( myImage, 0, 0, null);
// or whatever works best for you
}
As far as cropping the image, you just create a Shape object to use as a clipping shape. The call looks like:
// in paint() method
g2.clip( myClippingShape );
g2.drawImage( myImage, 0, 0, null );
Hope this helps!
Darrin