2012-10-28 152 views
2

我想知道我是如何改變位圖的位置並同時旋轉它的。我在畫布上繪畫。設置位圖的旋轉和位置

即時通訊目前使用這行代碼:

canvas.drawBitmap(bitmap, posX, posY, paint); 

,我認爲使用旋轉矩陣是最好的選擇嗎? 問題是,上面貼出的代碼行不是矩陣而是位置。

還有的代碼類似的一行:

canvas.drawBitmap(bitmap, matrix, paint); 

這一個取矩陣而不是位置。

我該怎麼做?

+0

您使用的是什麼技術/語言/平臺? –

+0

它被加了標籤! :) – Sebastian

回答

0

將位置作爲posMatrix放入矩陣中,並將其與旋轉矩陣相乘。 然後傳遞結果矩陣作爲參數。

編輯---

Matrix myTransformedMatrix = new Matrix(); 
myTransformedMatrix.setRotate(<rotation in dergrees>); 
myTransformedMatrix.setTranslate(<translation in points>); 

canvas.drawBitmap(bitmap, myTransformedMatrix, paint); 

對矩陣類的更多信息請訪問http://developer.android.com/reference/android/graphics/Matrix.html

+0

對不起,你能給我一段代碼嗎? ,因爲即時通訊不是那麼好:) – Sebastian

+0

爲什麼我不能設置位置和旋轉?它忽略了我的輪換? matrix.setRotate(90); \t \t \t matrix.setTranslate(pos_X,15); \t \t \t canvas.drawBitmap(bitmap,matrix,paint); – Sebastian

+0

嘗試使用matrix.postRotate(90); –

1
Matrix matrix = new Matrix(); 
matrix.SetRotate(90,pivotX,pivotY); 
matrix.PostTranslate(positionX,positionY); 
canvas.drawBitmap(bitmap, matrix , null); 

在口頭上 - 設置的位置旋轉之後。