如一张图片,需要在这张图片上画一个标记。图片旋转后,如何再找到这个标记的位置。如原图片的位置在(10,10)这个地方,图片旋转后,原先的(10,10)这个位置现在在哪里呢?求计算这个位置坐标的算法。

解决方案 »

  1.   

    //参数分别为:旋转角度,图片X中心,图片Y中心。 
    canvas.rotate(angle, getCenterX(),getCenterY()); 
    Image.setBounds(bounds); 
    Image.draw(canvas); 这是旋转画布来实现图片旋转,以图片中心来旋转,任意一点A(ax,ay),按旋转中心点(x,y)“顺时针”旋转任意角度k度后A'的坐标计算公式
    解:    x'=(ax-x)*cos(k) + (ay-y)*sin(k) + x;  此为最后的横坐标
        y'=-(ax-x)*sin(k) + (ay-y)*cos(k) + y;  此为最后的纵坐标
      

  2.   

    AndEngine引擎里有这个例子,类似活塞转动,始终能跟踪到位置不断上下左右变化的旋转的那个点,可以了解研究一下
      

  3.   


    我旋转用的是Bitmap和matrix.
      

  4.   

    Matrix m = new Matrix();
    m.postRotate(90);
    bmp = Bitmap.createBitmap(orgBmp, 0, 0, w, h, m, true);
      

  5.   

    我觉得,用Bitmp和Matrix来旋转的话是一样的,用Matrix的setRotate来旋转有两种方式
    public void setRotate (float degrees)Set the matrix to rotate about (0,0) by the specified number of degrees.
    //以(0,0)为原点旋转
    public void setRotate (float degrees, float px, float py)Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.
    //以(px,py)为原点旋转就是那方法是一样的,第一个Rotate
    公式   :X'=x*cos(n)+y*sin(n)
                  Y'=-x*sin(n)+y*cos(n)
    第二个Rotate和我上面说的计算方式是一样的