简体   繁体   English

Android Canvas:如何绘制具有自己旋转和枢轴点的多个位图?

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

Suppose that I have two bitmaps that I'd like to draw on a Canvas of a View . 假设我有两个要在ViewCanvas上绘制的位图。 The twist is that I want to draw the first bitmap rotated 30 degrees clockwise around one pivot point, and I want to draw the other bitmap 45 degrees counter-clockwise around another pivot point. 我要画的第一个位图是绕一个枢轴点顺时针旋转30度,而另一个位图是绕另一个枢轴点逆时针绘制45度。

I have the following stub in mind: 我谨记以下存根:

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();

Edit: 编辑:

Confirmed that it doesn't work. 确认它不起作用。 It just results in rotating the same canvas. 它只是导致旋转相同的画布。

Will I have to create 2 Bitmap s, rotate bitmapOne in one new Bitmap object, rotate bitmapTwo in the other, and draw them as normal in the destination canvas? 我是否需要创建2个Bitmap ,在一个新的Bitmap对象中旋转bitmapOne,在另一个对象中旋转bitmapTwo,然后在目标画布中正常绘制它们?

Do it this way: 这样做:

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