代码之家  ›  专栏  ›  技术社区  ›  David Manpearl

BlackBerry drawTexturedPath Rotate Move Anchor to Center of Image

  •  2
  • David Manpearl  · 技术社区  · 14 年前

    我知道如何使用DrawTexturePath以任意角度旋转BlackBerry位图图像。但是,旋转定位点位于图像的左上角。如何将锚定移动到图像的中心?

    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 )

    -大卫,提前谢谢你 Pixelmonks.com

    1 回复  |  直到 12 年前
        1
  •  1
  •   G B    12 年前

    To rotate around the center, you need to displace your bitmap before the rotation: 而不是

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

    你应该使用

    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.