Home  >  Article  >  Java  >  Introduction to various methods of image mirroring in android development

Introduction to various methods of image mirroring in android development

Y2J
Y2JOriginal
2017-04-22 10:06:452224browse

There are many ways to do image mirroring in android. I learned it today. Friends who are interested can refer to

The two methods are as follows:

The code is as follows:

//Method one

Matrix matrix = new Matrix(); 
matrix.postScale(leftOrRight, 1, bmpW/2, bmpH/2);//前两个是xy变换,后两个是对称轴中心点 
matrix.postTranslate(x, y); 
canvas.drawBitmap(bmpLuffy[0], matrix, paint);

//Method two

// 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 one, using matrix (3x3 ) Matrix:
1. First use postScale to flip the image with the point (bmpW/2, bmpH/2) as the center and x=bmpW/2 as the symmetry axis;
2. Use postTranslate , move the picture to (x, y) coordinates
Method 2, flip the canvas (omitted)
Pay attention to the following issues:
For bmpW and bmpH refer to the width of the picture used High, you need to use the image bmp.getWidth() and bmp.getHeight() to obtain it.
Cannot use the size seen on the PC, otherwise misalignment may occur!

The above is the detailed content of Introduction to various methods of image mirroring in android development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn