Flipping a bitmap in android help?

Baruch picture Baruch · Oct 15, 2011 · Viewed 14k times · Source

I want to save up memory for my game and I wanted to ask you because I couldn't find anything and last time that I asked something here I got a good answer. Can i flip the bitmap inside eclipse so i could save on memory for sprites? All the tutorials that i found were about rotating and not flipping. The tutorials for flipping a bitmap were only for open Gl or something like that. Please help me. I've been looking up for tutorials in google but i gave up at page 5. Can anyone help me? Does anyone have a good tutorial? By the way I am using a canvas. Thanks!

I get a force close everytime I try to run it... can u figure it out? here is my code:

       Matrix flipHorizontalMatrix = new Matrix();
       flipHorizontalMatrix.setScale(-1,1);
       flipHorizontalMatrix.postTranslate(0, canvas.getHeight()-arrowL.getHeight());
       canvas.drawBitmap(arrowL, flipHorizontalMatrix, null);

I want the arrow to be at the bottom right corner.

Answer

Christopher Perry picture Christopher Perry · Oct 15, 2011

Since you're using Canvas, why not try the drawBitmap (Bitmap bitmap, Matrix matrix, Paint paint) method. Use a Matrix that flips the x coordinates.

You can do something like this:

Matrix flipHorizontalMatrix = new Matrix();
flipHorizontalMatrix.setScale(-1,1);
flipHorizontalMatrix.postTranslate(myBitmap.getWidth(),0);

canvas.drawBitmap(myBitmap, flipHorizontalMatrix, myPaint);