很莫名其妙的,前摄默认镜像,原来是为了前摄拍字体正确显示,比如自拍,前摄拍摄的人像虽左右镜像了,但如果后面有字牌显示,字体会显示正常而不是翻转。但现在需求是满足普遍的前摄原生代码不带镜像修改,需要把预览和保存的图片进行左右翻转,那么就需要找到相应的修改位置才行。
以下就是相关修改点:直接修复前摄镜像显示 即可正常显示
充分利用此方法:
PhotoModeHelper.rotateAndMirror(bitmap, orientation, true);
和
matrix.postScale(-1, 1);
1 ./vendor/mediatek/proprietary/packages/apps/Camera2/common/src/com/mediatek/camera/common/utils/CameraUtil.java
//*/add package
import android.graphics.BitmapFactory;
import com.mediatek.camera.common.mode.photo.PhotoModeHelper;
import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;
//*/
添加在最后的方法//*/add sub camera mirror method mirrorJpegData
public static byte[] mirrorJpegData (byte[] jpegData, int orientation) {
byte[] dest = jpegData;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inMutable = true;
Bitmap b = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, opts);
b = PhotoModeHelper.rotateAndMirror(b, orientation, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, baos);
dest = baos.toByteArray();
b.recycle();
return dest;
}
//*/
2. /vendor/mediatek/proprietary/packages/apps/Camera2/common/src/com/mediatek/camera/common/mode/photo/PhotoMode.java
@Override
public void onPostViewCallback(byte[] data) {
LogHelper.d(TAG, "[onPostViewCallback] data = " + data + ",mIsResumed = " + mIsResumed);
CameraSysTrace.onEventSystrace(POST_VIEW_CALLBACK, true, true);
if (data != null && mIsResumed) {
//will update the thumbnail
int rotation = CameraUtil.getJpegRotationFromDeviceSpec(Integer.parseInt(mCameraId),
mIApp.getGSensorOrientation(), mIApp.getActivity());
Bitmap bitmap = BitmapCreator.createBitmapFromYuv(data,
ThumbnailHelper.POST_VIEW_FORMAT,
ThumbnailHelper.getThumbnailWidth(),
ThumbnailHelper.getThumbnailHeight(),
mIApp.getAppUi().getThumbnailViewWidth(),
rotation);
//*/ add sub camera mirror
if (mCameraId.equals(FRONT_CAMERA_ID)) {//BACK_CAMERA_ID
Matrix m = new Matrix();
m.postScale(-1, 1);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
}
//*/mIApp.getAppUi().updateThumbnail(bitmap);
}
CameraSysTrace.onEventSystrace(POST_VIEW_CALLBACK, false, true);
}
===============
保存数据是通过PhotoMode.java文件中的saveData方法实现,具体修改参照如下:引用方法
private void saveData (byte[] data) {
if (data != null) {
//*/ add. sub camera mirror
if (mCameraId.equals(FRONT_CAMERA_ID)) {//BACK_CAMERA_ID
data = CameraUtil.mirrorJpegData(data, 0);
}
//*///check memory to decide whether it can take next picture.
//if not, show saving
ISettingManager.SettingController controller = mISettingManager.getSettingController();
String dngState = controller.queryValue(KEY_DNG);
long saveDataSize = data.length;
if (dngState != null && "on".equalsIgnoreCase(dngState)) {
saveDataSize = saveDataSize + DNG_IMAGE_SIZE;
}
synchronized (mCaptureNumberSync) {
mCapturingNumber ++;
mMemoryManager.checkOneShotMemoryAction(saveDataSize);
}
String fileDirectory = mICameraContext.getStorageService().getFileDirectory();
Size exifSize = CameraUtil.getSizeFromSdkExif(data);
ContentValues contentValues = mPhotoModeHelper.createContentValues(data,
fileDirectory, exifSize.getWidth(), exifSize.getHeight());
mICameraContext.getMediaSaver().addSaveRequest(data, contentValues, null,
mMediaSaverListener);
}
}
到此完结撒花!