So, my goal is to flip the image horizontally and then draw it on the canvas. I am currently using canvas.scale (-1,1), which works efficiently and draws the image horizontally, however it also screws with x axis values, where the x position will be 150 before the scale, and after I have to switch to -150 for rendering in the same place.
My question is, how can I make the x value be 150 in both cases without having to adjust the x position after the scale? Is there a more efficient way to do this without clicking on performance?
, :
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);
, , . , , ImageButton. , , . onDraw(Canvas) :
onDraw(Canvas)
@Override protected void onDraw(final Canvas canvas) { // Scale the canvas, offset by its center. canvas.scale(-1f, 1f, super.getWidth() * 0.5f, super.getHeight() * 0.5f); // Draw the button! super.onDraw(canvas); }
Have you tried to repeat canvas.scale(-1, 1)? It will effectively remove the transformation, as two negatives make it positive.
canvas.scale(-1, 1)