Android系统相机在使用前置摄像头拍照的时候,最终会将拍下的画面做镜像翻转,来达到真实的视角效果,但由于Android手机大多将前置摄像头摆在左右两边(iPhone在靠中间的位置,效果会好很多),导致翻转后与拍照预览的画面还是会有较大的差别,所以我们这里就再做一次镜像将图片翻转回去。
图片镜像
public Bitmap convertBmp(Bitmap bmp) {
int w = bmp.getWidth();
int h = bmp.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(-1, 1); // 镜像水平翻转
Bitmap convertBmp = Bitmap.createBitmap(bmp, 0, 0, w, h, matrix, true);
return convertBmp;
}
图片的翻转主要用到变换矩阵中的缩放操作,x轴都乘-1,y轴保持不变。
图片保存
private void saveBitmap() {
try {
File outFile = new File(Utils.getRootPath(),
System.c