Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flipping a bitmap in android help?

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.

like image 980
Baruch Avatar asked Oct 14 '11 23:10

Baruch


People also ask

How do you flip an image on android?

With the image open in the editor, switch to the “Tools” tab in the bottom bar. A bunch of photo editing tools will appear. The one that we want is “Rotate.” Now tap the flip icon in the bottom bar.

How do I flip my screen vertically on Android?

Tap the crop icon in the bottom as it has the flip options, then tap Rotate from the newly opened toolbar. You can now tap Flip Horizontal or Flip Vertical to flip your photo. When you're done flipping the photo, tap Next in the top-right.

How do you draw a bitmap?

To draw on a bitmap, use the image control's canvas and attach the mouse-event handlers to the appropriate events in the image control. Typically, you would use region operations (fills, rectangles, polylines, and so on).


1 Answers

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);
like image 71
Christopher Perry Avatar answered Oct 05 '22 23:10

Christopher Perry