There are many ways to create image images in android. Today we are learning!
The two methods are as follows:
[Java]
// Method 1
Matrix matrix = new Matrix ();
Matrix. postScale (leftOrRight, 1, bmp w/2, bmp h/2); // the first two are xy transformations, and the last two are the center points of the symmetric axis.
Matrix. postTranslate (x, y );
Canvas. drawBitmap (bmpLuffy [0], matrix, paint );
// Method 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 a matrix (3x3) matrix:
1. First, use postScale to take the image as the center (bmp w/2, bmp h/2) and x = bmp w/2 as the axis of symmetry;
2. Use postTranslate to move the image to the (x, y) coordinate.
Method 2: Flip the canvas (omitted)
Note the following:
For the values of bmp W and bmp H, the width and height of the image must be obtained using bmp. getWidth () and bmp. getHeight,
You cannot use the size shown on the PC. Otherwise, misplacement may occur!
-----------------------------------------------------------------------
From Akai's column