繪製到畫布中時,您可以對要繪製的形狀執行各種轉換。
所以,如果你首先要旋轉整個娃娃,你應該在繪製娃娃之前進行轉換。然後,您可以在該轉換中轉換每個身體部位。例如,一條腿的娃娃。
//save the canvas transformation state
canvas.save();
//first move the whole doll
canvas.translate(dollPosition.x,dollposition.y);
//we are now inside the coordinate system of the doll
//draw head (Position is now relative to the center of the doll position)
canvas.drawCircle(dollHeadPosition.x, dollHeadPosition.y, headRadius, paint);
//save the canvas to transform leg independently
canvas.save();
canvas.translate(legPosition.x,legPosition.y);
//draw leg
canvas.drawRect(...);
//restore the canvas to get back to your doll coordinate system
canvas.restore()
//restore canvas to get to global coordinate system
canvas.restore()
有各種轉換,如旋轉和傾斜等。只需使用自動完成來了解它們的寫法。
(我希望壓痕清楚,它是如何工作)
非常好,我設法繪製整個娃娃,現在調整大小,謝謝你的帖子。但我仍然無法理解我如何旋轉娃娃。例如,我想旋轉頭部和身體,但它從右向左旋轉,而不是從左向右旋轉。我該怎麼做呢? – 2012-02-22 14:51:32
如果我理解正確,你有一個逆時針旋轉,但希望它是時鐘方面?然後,您可以簡單地插入旋轉角度的負值。 如果我回答了您的問題,請接受我的回答,並針對您的新問題提出一個新問題。 – devsnd 2012-02-22 21:28:05