vendor/mediatek/proprietary/packages/apps/Camera2
exist
common/src/com/mediatek/camera/common/mode/photo/PhotoMode.java
on every save operation
privatevoid saveData(byte[] data) {
At the beginning, add and change the value of the parameter data
if(mCameraId.equals("1")){
data =CameraUtil.mirrorJpegData(data,0);
}
Then in common/src/com/mediatek/camera/common/utils/CameraUtil.java
join method
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.mediatek.camera.common.mode.photo.PhotoModeHelper;
importjava.io.ByteArrayOutputStream;
public static byte[] mirrorJpegData(byte[] jpegData, int orientation) {
byte[] dest = jpegData;
BitmapFactory.Options opts = newBitmapFactory.Options();
opts.inMutable = true;
Bitmap b =BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, opts);
b = PhotoModeHelper.rotateAndMirror(b,0, true);
ByteArrayOutputStream baos = newByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG,100, baos);
dest = baos.toByteArray();
b.recycle();
return dest;
}
Notice! At this time, the thumbnail after taking a picture is still a non-mirror image, and the thumbnail needs to be changed, which is the same.
host/src/com/mediatek/camera/ui/ThumbnailViewManager.java
在public void updateThumbnail(Bitmap bitmap) {
Change the bitmap at the beginning
bitmap= PhotoModeHelper.rotateAndMirror(bitmap, 0, true);
Attention package
import com.mediatek.camera.common.mode.photo.PhotoModeHelper;
This thumbnail is initially host/src/com/mediatek/camera/ui/CameraAppUI.java
call to
public void updateThumbnail(final Bitmapbitmap) {
But it stipulates that the final cannot be changed, (deleting it is useless, the caller has been fixed), and then adjusted
mThumbnailViewManager.updateThumbnail(bitmap);
If mCameraId is 1, it means the front camera (selfie), if it is 0, it means the rear camera
source code this string assignment
mCameraId= getCameraIdByFacing(mDataStore.getValue(
KEY_CAMERA_SWITCHER, null,mDataStore.getGlobalScope()));
mainly
common/src/com/mediatek/camera/common/mode/photo/PhotoModeHelper.java
There is a method originally designed here, but this method has not actually been implemented, so the default is non-mirror. The mirroring algorithm has been designed, so pass a true for the third parameter.
public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) {
if ((degrees != 0 || mirror) &&b != null) {
Matrix m = new Matrix();
// Mirror first.
// horizontal flip + rotation =-rotation + horizontal flip
if (mirror) {
m.postScale(-1, 1);
degrees = (degrees + 360) %360;
if (degrees == 0 || degrees ==180) {
m.postTranslate(b.getWidth(), 0);
} else if (degrees == 90 ||degrees == 270) {
m.postTranslate(b.getHeight(),0);
} else {
throw newIllegalArgumentException("Invalid degrees=" + degrees);
}
}
if (degrees != 0) {
// clockwise
m.postRotate(degrees, (float)b.getWidth() / 2, (float) b.getHeight() / 2);
}
try {
Bitmap b2 =Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
if (b != b2) {
b.recycle();
b = b2;
}
} catch (OutOfMemoryError ex) {
// We have no memory to rotate.Return the original bitmap.
ex.printStackTrace();
}
}
return b;
}