如何反转绘制到画布中的图像?
我有以下几点:
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(),我做错了什么?
发布于 2012-08-08 07:39:46
好吧,我是这样解决的:
Rect currentBounds = currentBounds();
currentBounds.offset((int)offset.x(), (int)offset.y());
float scale = (float) currentBounds.width() / (float) image.current().getWidth();
boolean leftMovement = movingLeft();
Matrix matrix = new Matrix();
matrix.setScale(leftMovement ? -scale : scale, scale);
matrix.postTranslate(leftMovement ? currentBounds.right : currentBounds.left, currentBounds.top);
canvas.drawBitmap(image.current(), matrix, Paints.BLANK);但是这个"leftMovement ? currentBounds.right : currentBounds.left“看起来不太对劲
https://stackoverflow.com/questions/11852762
复制相似问题