开发者

BlackBerry drawTexturedPath Rotate Move Anchor to Center of Image

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(ang开发者_如何学Gole32);
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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜