簡體   English   中英

Android Canvas:如何繪制具有自己旋轉和樞軸點的多個位圖?

[英]Android Canvas: How do I draw multiple bitmaps with their own rotations and pivot points?

假設我有兩個要在ViewCanvas上繪制的位圖。 我要畫的第一個位圖是繞一個樞軸點順時針旋轉30度,而另一個位圖是繞另一個樞軸點逆時針繪制45度。

我謹記以下存根:

canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(30, pivotX, pivotY);
canvas.drawBitmap(bitmapOne, x1, y1, antiAliasPaint);
canvas.rotate(-75, otherPivotX, otherPivotY);
canvas.drawBitmap(bitmapTwo, x2, y2, antiAliasPaint);
canvas.restore();

編輯:

確認它不起作用。 它只是導致旋轉相同的畫布。

我是否需要創建2個Bitmap ,在一個新的Bitmap對象中旋轉bitmapOne,在另一個對象中旋轉bitmapTwo,然后在目標畫布中正常繪制它們?

這樣做:

canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(30, pivotX, pivotY);
canvas.drawBitmap(bitmapOne, x1, y1, antiAliasPaint);
canvas.restore();

canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(-75, otherPivotX, otherPivotY);
canvas.drawBitmap(bitmapTwo, x2, y2, antiAliasPaint);
canvas.restore();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM