因项目预研需要,采用android camera2进行前置、后置摄像头拍照、拍视频,在用前置摄像头进行拍照时,照片预览是正的,保存本地照片也是正的,只不过照片里的内容进行了左右镜像,现在需要将照片里的内容再左右镜像回来,找了很多的方法,以下两种亲测可行:
第一种:
Bitmap oldMap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
matrix.setScale(-1.0f, 1.0f);
oldMap = Bitmap.createBitmap(oldMap, 0, 0, oldMap.getWidth(), oldMap.getHeight(), matrix, true);
try {
FileOutputStream out = new FileOutputStream(mFile);
oldMap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
第二种:
Bitmap oldMap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
Paint paint=new Paint();
Bitmap newMap= Bitmap.createBitmap(oldMap.getWidth(), oldMap.getHeight(), Bitmap.Config.RGB_565);
Canvas canvas=new Canvas(newMap);
canva