2

I know how to rotate a BlackBerry Bitmap image an arbitrary angle with drawTexturePath. But, The Rotation Anchor is at the top-top left of the image. How do I move the Anchor to the center of the image?

This code uses Graphics.drawTexturedPath to rotate around top-left corner:

int[] x = new int[] {0, width, width, 0};
int[] y = new int[] {0, 0, height, height};
int angle32 = Fixed32.toFP(angleDegrees);
int dux = Fixed32.cosd(angle32);
int dvx = -Fixed32.sind(angle32);
int duy = Fixed32.sind(angle32);         
int dvy = Fixed32.cosd(angle32);       
graphics.drawTexturedPath(x, y, null, null, 0, 0, dvx, dux, dvy, duy, bitmapImage);

How do I modify this code to rotate around the center of the image with drawTexturedPath (http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Graphics.html#drawTexturedPath)?

FYI, a similar post describes other 2D afine transformations with drawTexturedPath including skew and some 3D effects here: "BlackBerry - image 3D transform" (BlackBerry - image 3D transform).

-Thanks in advance, David Pixelmonks.com

Community
  • 1
  • 1
David Manpearl
  • 12,362
  • 8
  • 55
  • 72

1 Answers1

1

To rotate around the center, you need to displace your bitmap before the rotation: instead of

int[] x = new int[] {0, width, width, 0};
int[] y = new int[] {0, 0, height, height};

you should use

int[] x = new int[] {-width / 2, width / 2, width / 2, -width / 2};
int[] y = new int[] {-height / 2, -height / 2, height / 2, height / 2};

then apply the transformation, and add again width / 2 to all your x-values, and height / 2 to your y-values.

G B
  • 2,951
  • 2
  • 28
  • 50