2014-02-15 41 views
0

我需要在特定點處旋轉圖像,然後將其轉換爲屏幕上的特定點。
我想旋轉它的點位於圖片的中心。特定點處的旋轉和轉換

traslation工作,但旋轉不。

我有一個位圖矢量,我正在使用畫布和矩陣。

代碼:

for (Bitmap image:images) 
{ 
    //rotation 
    double angle=Math.toDegrees(rotation); 
    Matrix matrix=new Matrix(); 
    matrix.postRotate((float)angle,finalMap.getWidth()/2-1,0); 

    //transform  
    matrix.setTranslate(position.x,position.y); 

    //print on screen  
    c.drawBitmap(image,matrix, paint); 
} 

回答

1

試着改變你的旋轉/平移調用像這樣(在正是這個順序):

matrix.setTranslate(position.x,position.y); 
matrix.preRotate((float)angle,finalMap.getWidth()/2-1,0); 

它不工作,你擁有了它目前的方式的原因,那是你setTranslate()調用丟棄你以前做過的旋轉,只是用在單位矩陣上執行的翻譯來代替它。以「set」前綴開頭的矩陣轉換方法只會應用轉換,就好像在它們之前沒有發生任何事情。

如果你想了解更多,這是一個有用的答案:https://stackoverflow.com/a/8197896/2464728

+0

謝謝你,這是非常有用的和有用的信息。旋轉工作! – tzahibs

+0

@ user1440724很高興能幫到你!感謝您接受答案。 – Matej

0

什麼是 '旋轉不' 呢?它如何不如你期望的那樣做? 我最初想知道使用0作爲y旋轉點。

+0

「旋轉不會」 =的圖象不rotate.the 0是圖像的頂部。 **我想旋轉特定點像鐘擺**的圖片。 [鏈接] http://images.tutorvista.com/content/wave-motion-sound/simple-pendulum.gif – tzahibs