1

我需要帮助将旋转视图中的选定点转换回原始图像中的对应点。因此,例如,如果我在旋转视图中单击左上角 ( 0,0 ),它应该对应于原始图像中的 (0,1280)。

无论旋转如何,解决方案都可以加分。

Original Image ( 1920 x 1280 )     Rotated View ( for display on phone )
+----------------------------+     +-----------------+
|(0,0)                       |     |(0,0)            |  ( 1280 x 1920 )
|                            |     |                 |
|                            |     |       x         |
|    x                       |     |    ( click )    |
|    ( what is this point )  |     |                 |
|                            |     |                 |
|                            |     |                 |
+----------------------------+     |                 |
                      (1920,1280)  |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   |                 |
                                   +-----------------+
                                                      (1280,1920)

更新


    /*
    This is how I build the matrix used to perform the initial rotation from the original to     the rotated image. This matrix also includes scaling 

    Code base: Android/Java
    bitmap ( bitmap i'm scaling/rotating )
    canvas ( the canvas being drawn to )

    Note: bitmap is in landscape mode / canvas is in portrait

    */

    Matrix matrix = new Matrix();
    float centerX = canvas.getWidth() >> 1;
    float centerY = canvas.getHeight() >> 1;

    rAngle = 90;
    scaleH = ((float) canvas.getHeight()) / bitmap.getWidth();
    scaleW = ((float) canvas.getWidth()) / bitmap.getHeight();

    scaler.preScale(scaleH, scaleW);
    scaler.postRotate(rAngle, centerY, centerX);

    float nx = (canvas.getHeight() - canvas.getWidth()) / 2;
    scaler.postTranslate(-nx, nx);

    canvas.drawBitmap(bitmap,scaler,null);

我几乎不是一个数学家,所以任何牵手都会受到赞赏。:)

4

1 回答 1

1

下标O表示原始帧中的坐标,下标R表示旋转帧中的坐标:

X O = Y R
Y O = maxX R - X R

框架的四个角给我们:

对于旋转框架的左上角 (0,0)

X O = 0
Y O = 1279 - 0 = 1279
(0, 1279)

对于右上角,(1279, 0):

X O = 0
Y O = 1279 - 1279 = 0
(0, 0)

对于左下角,(0, 1919):

X O = 1919
Y O = 1279 - 0 = 1279
(1919, 1279)

对于右下角,(1279、1919):

X O = 1919
Y O = 1279 - 1279 = 0
(1919, 0)

于 2014-03-12T18:27:23.583 回答