Here, this code will help you learn alot about AffineTransforms which is exactly what you need.
It will randomly rotate 3 images, enable anti-alisning and even make the pics semi-transparent! :D
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
public class ImageTest extends Applet
{
// the Images to render
private Image[] images;
private AlphaComposite alpha;
// filename description of our images
private final String[] filenames =
{ "image1.jpg", "image2.jpg", "image3.gif" };
public void init()
{
// get the base URL
java.net.URL appletBaseURL = getCodeBase();
alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f);
// allocate memory for the images and load 'em in
int n = filenames.length;
images = new Image[n];
for(int i = 0; i < n; i++)
{
images[i] = getImage(appletBaseURL, filenames[i]);
}
}
public void paint(Graphics g)
{
// cast the sent Graphics context to get a usable Graphics2D object
Graphics2D g2d = (Graphics2D)g;
// save an identity transform
final AffineTransform identity = new AffineTransform();
// used to transform our images
AffineTransform at = new AffineTransform();
Random r = new Random();
int width = getSize().width;
int height = getSize().height;
int numImages = filenames.length;
// render 100 images, each with a random transformation
for(int i = 0; i < 100; i++)
{
// clear the transformation
at.setTransform(identity);
// randomly set up the translation and rotation
at.translate(r.nextInt()%width, r.nextInt()%height);
at.rotate(Math.toRadians(360*r.nextDouble()));
at.scale(2*r.nextDouble(), 2*r.nextDouble());
// draw one of the images
g2d.setColor(Color.BLACK);
g2d.setFont(new Font("Helvetica", Font.BOLD, 76));
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.drawString("Text Antialiasing On", 50, 50);
g2d.setComposite(alpha);
g2d.drawImage(images[i%numImages], at, this);
}
}
}// ImageTest
// <Applet code=ImageTest width=300 height=300></Applet>
-Adam