简体   繁体   中英

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(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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM