【问题标题】:Android Canvas: How do I draw multiple bitmaps with their own rotations and pivot points?Android Canvas:如何使用自己的旋转和枢轴点绘制多个位图?
【发布时间】:2016-05-11 10:20:07
【问题描述】:

假设我想在CanvasView 上绘制两个位图。扭曲是我想绘制第一个位图围绕一个枢轴点顺时针旋转 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 个Bitmaps,在一个新的Bitmap 对象中旋转 bitmapOne,在另一个对象中旋转 bitmapTwo,然后在目标画布中正常绘制它们?

【问题讨论】:

    标签: android android-canvas


    【解决方案1】:

    这样做:

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

    【讨论】:

    • 它有效。我还没有探索过canvas.save()canvas.restore() 是如何工作的,所以我不知道这一点。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多