I'm drawing an image using Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint). I want to flip the image for left and right movement but I cant use a matrix with this method. I can rotate using canvas.rotate but thats no use for flipping, any ideas?
0
votes
1 Answers
5
votes
You can do it using scale + translate. The following code flips left-to-right:
canvas.scale(-1, 1);
canvas.translate(-canvas.getWidth(), 0);
canvas.drawBitmap(bmp, 0, 0, null);
canvas.setMatrix(null);
Without translate your bitmap will be drawn with negative coordinates - outside the left edge of screen.