I got this from someone else on the forum:
public void rotateImage() {
int x0 = 0 ,y0 = 0;
deg=deg%360;
newImWidth=(int)(imWidth*Math.abs(cos[deg])+imHeight*Math.abs(sin[deg]));
newImHeight=(int)(imWidth*Math.abs(sin[deg])+imHeight*Math.abs(cos[deg])); // Calculate width and height of the new image
if((deg>=0)&&(deg<90)) {
x0=(int)(imHeight*sin[deg]);
}
if((deg>=90)&&(deg<180)) {
y0=newImWidth-(int)(imWidth*sin[deg]);
x0=newImWidth;
}
if((deg>=180)&&(deg<270)) {
y0=newImHeight;
x0=-(int)(imWidth*cos[deg]);
}
if((deg>=270)&&(deg<360)) {
y0=-(int)(imHeight*sin[deg]);
}
newImPix=new int[newImWidth*newImHeight];
for(int i=0; i<newImWidth; i++){ // Check for every pixel of the new drawing which one it should be...
for(int j=0; j><newImHeight; j++){
int x=i-x0;
int y=j-y0;
int oldx=(int)(x*cos[deg]+y*sin[deg]); // Old coords of the pixel of the rotated image
int oldy=(int)(y*cos[deg]-x*sin[deg]);
if((oldx><imWidth)&&(oldy><imHeight)&&(oldx>=0)&&(oldy>=0){ //if these coords are within the reach of the old picture: take that color...
newImPix[i+j*newImWidth]=imPix[oldx+oldy*imWidth];
}else{
newImPix[i+j*newImWidth]=0x00ffffff; // transparent white
}
}
}
}