如何反轉繪製到畫布中的圖像?在畫布上反轉繪製位圖
我有以下幾點:
canvas.save();
canvas.drawBitmap(image.current(), null, currentBounds(), Paints.BLANK);
canvas.restore();
我怎樣才能讓現在的影像drawed fliped 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(),我做錯了什麼?
我認爲[這](HTTP:/ /stackoverflow.com/a/7775153/314784)是最好的方法。它使用矩陣,但並不那麼難。 – 2012-08-07 19:33:28
使用矩陣應該是直截了當的。 – Doomsknight 2012-08-07 19:34:07
可能是最好的方法,請閱讀我編輯的答案,看看新的錯誤 – 2012-08-07 23:27:54