【发布时间】:2012-08-07 19:28:24
【问题描述】:
如何将绘制到 Canvas 中的图像反转?
我有以下:
canvas.save();
canvas.drawBitmap(image.current(), null, currentBounds(), Paints.BLANK);
canvas.restore();
如何使当前图像在 x 轴上翻转到 currentBounds() 中?
我已经找到了一些表明使用 Matrix 的答案,但我想知道是否有更简单的方法?这样的画图打开了一些标志。
编辑:
以下是我对矩阵变换的尝试:
Rect currentBounds = currentBounds();
currentBounds.offset((int)offset.x(), (int)offset.y());
float scale = image.current().getWidth() / currentBounds.width();
Matrix matrix = new Matrix();
matrix.setScale(- scale - 1, scale + 1);
matrix.postTranslate(currentBounds.left, currentBounds.top);
canvas.drawBitmap(image.current(), matrix, Paints.BLANK);
canvas.drawRect(currentBounds, Paints.STROKE_BLUE);
本次抽签结果如下:
https://dl.dropbox.com/u/28683814/game.png
可以看出,精灵正在从 0,0 向左绘制,并且没有完全完成 currentBounds(),我做错了什么?
【问题讨论】:
-
我认为this 是最好的方法。它使用矩阵,但并不难。
-
使用矩阵应该是直截了当的。
-
可能是最好的方法,请阅读我编辑的答案以查看新错误