rotate bitmap..

please help me to rotate a image about specific point (e.g center of image,not Point(0,0).Thanks you!
[115 byte] By [qduong00c1a] at [2007-9-28 4:32:57]
# 1
Are you rotating with an AffineTransform? If so, before the rotation you need to translate it by (-x, -y) and after the rotation you need to translate it by (x, y).
YATArchivista at 2007-7-8 0:06:19 > top of Java-index,Other Topics,Algorithms...
# 2

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

}

}

}

}

shishthemoomina at 2007-7-8 0:06:19 > top of Java-index,Other Topics,Algorithms...