views:

67

answers:

2

So my aim is to flip an image horizontally then draw it on a canvas. Currently I'm using canvas.scale(-1,1) which effectively works and draws the image horizontally, however it also screws with the x axis values where before the scale the x position would be 150 and after I'd have to switch it to -150 to render in the same spot.

My question is, how can I make it so the x value is 150 in both cases without having to adjust the x position after the scale? Is there a more effective way to do this without taking a hit on performance?

A: 

Did you try repeating the canvas.scale(-1, 1)? It will effectively remove the transformation, since two negatives make a positive.

nasufara
A: 

I've fixed this by applying the transformation to the bitmap prior to ever using it like this:

public void applyMatrix(Matrix matrix) {
    mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, 
      mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
}
...
Matrix matrix = new Matrix();
matrix.preScale(-1, 1);
mSprite.applyMatrix(matrix);
methodin