# Discussion Board

1. 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

2. Hi all,

No Help?

3. Rotating Images in Java ME

A quick search could have helped you rather than waiting..

Regards
Gopal

4. 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

5. 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

6. Originally Posted by sachin_t14
Just need to know what are the parameters cx & cy.
It seems to be the centre of rotation
No use of dd int array.
Check once more, it is an output argument and is set at the end. Contains the new top-left coordinates for the image.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.