Hi all,
i need to rotate a j2me image with any angle like (10,30,50,110,200........... etc),
any one can help on this?
thanks a lot,
Omar
Hi all,
i need to rotate a j2me image with any angle like (10,30,50,110,200........... etc),
any one can help on this?
thanks a lot,
Omar
Rotating Images in Java ME
A quick search could have helped you rather than waiting..
Regards
Gopal
Hi all,
I made rotation by any angle in J2me i found this on a tutorial and i made set of enhancements on it.
If any one need to try it here it is:
public Image rotate(Image imgSource, int cx, int cy, double theta, int dd[]) {
if (Math.abs(theta % 360) < 0.1) {
return imgSource;
}
int w1 = imgSource.getWidth();
int h1 = imgSource.getHeight();
int srcMap[] = new int[w1 * h1];
imgSource.getRGB(srcMap, 0, w1, 0, 0, w1, h1);
int dx = cx;
int dy = cy;
double dr = Math.sqrt(dx * dx + dy * dy);
int wh2 = (int) (2 * dr + 1);
int destMap[] = new int[wh2 * wh2];
double radian = theta * Math.PI / 180;
for (int i = 0; i < w1; i++) {
for (int j = 0; j < h1; j++) {
int destX = (int) (dr + (i - cx) * Math.cos(radian) + (j - cy) * Math.sin(radian));
int destY = (int) (dr + (j - cy) * Math.cos(radian) - (i - cx) * Math.sin(radian));
destMap[(int) wh2 * destY + (int) destX] = srcMap[j * w1 + i];
destMap[(int) wh2 * (int) destY + (int) destX + 1] = srcMap[j * w1 + i];
}
}
dd[0] = (int) (cx - dr);
dd[1] = (int) (cy - dr);
return Image.createRGBImage(destMap, wh2, wh2, true);
}
thanks a lot
Last edited by omarhassan123; 2010-08-08 at 14:03.
Hi Omarhassan,
Nice method.... I tried & it worked. Just need to know what are the parameters cx & cy. No use of dd int array.
Thanks a lot