android image rendering of one of several methods for image mirroring

  • 2020-05-09 19:16:37
  • OfStack

There are many ways to do image mirroring in android.
The two methods are as follows:
 
// methods 1 
Matrix matrix = new Matrix(); 
matrix.postScale(leftOrRight, 1, bmpW/2, bmpH/2);// The first two are xy Transformation, the last two are the center points of the axis of symmetry  
matrix.postTranslate(x, y); 
canvas.drawBitmap(bmpLuffy[0], matrix, paint); 
// methods 2 
// canvas.save(); 
// canvas.scale(-1, 1, x + bmpLuffy[0].getWidth() / 2, y + bmpLuffy[0].getHeight() / 2); 
// canvas.drawBitmap(bmpLuffy[0], x, y, paint); 
// canvas.restore(); 

Method 1, use the matrix method (3x3) matrix:
1. First, postScale is used to center the picture at the point (bmpW/2,bmpH/2), with x=bmpW/2 as the axis of symmetry;
2. Use postTranslate to move the image to the coordinates (x,y)
Method 2. Flip the canvas (omitted)
Note the following questions:
Where bmpW and bmpH refer to the width and height of the image used, images bmp.getWidth () and bmp.getHeight () need to be obtained.
Do not use the size seen on PC, otherwise misalignment may occur!
-----------------------------------------------------------------------
If you are not familiar with Matrix, you can refer to the api documentation or web articles

Related articles: