我想知道我是如何改變位圖的位置並同時旋轉它的。我在畫布上繪畫。設置位圖的旋轉和位置
即時通訊目前使用這行代碼:
canvas.drawBitmap(bitmap, posX, posY, paint);
,我認爲使用旋轉矩陣是最好的選擇嗎? 問題是,上面貼出的代碼行不是矩陣而是位置。
還有的代碼類似的一行:
canvas.drawBitmap(bitmap, matrix, paint);
這一個取矩陣而不是位置。
我該怎麼做?
我想知道我是如何改變位圖的位置並同時旋轉它的。我在畫布上繪畫。設置位圖的旋轉和位置
即時通訊目前使用這行代碼:
canvas.drawBitmap(bitmap, posX, posY, paint);
,我認爲使用旋轉矩陣是最好的選擇嗎? 問題是,上面貼出的代碼行不是矩陣而是位置。
還有的代碼類似的一行:
canvas.drawBitmap(bitmap, matrix, paint);
這一個取矩陣而不是位置。
我該怎麼做?
將位置作爲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
Matrix matrix = new Matrix();
matrix.SetRotate(90,pivotX,pivotY);
matrix.PostTranslate(positionX,positionY);
canvas.drawBitmap(bitmap, matrix , null);
在口頭上 - 設置的位置旋轉之後。
您使用的是什麼技術/語言/平臺? –
它被加了標籤! :) – Sebastian