Android 解决MTK相机前摄镜像问题

很莫名其妙的,前摄默认镜像,原来是为了前摄拍字体正确显示,比如自拍,前摄拍摄的人像虽左右镜像了,但如果后面有字牌显示,字体会显示正常而不是翻转。但现在需求是满足普遍的前摄原生代码不带镜像修改,需要把预览和保存的图片进行左右翻转,那么就需要找到相应的修改位置才行。

以下就是相关修改点:直接修复前摄镜像显示 即可正常显示

充分利用此方法:

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);

}

}

到此完结撒花!

相关推荐
古月居GYH8 小时前
【图像与点云融合教程(五)】海康相机 ROS2 多机分布式实时通信功能包
分布式·数码相机
创小董4 天前
履带式排爆演习训练机器人技术详解
数码相机·机器人
shuxianshrng5 天前
违停拍照和闯红灯拍照有什么区别吗
人工智能·数码相机·计算机视觉·视觉检测
图灵追慕者5 天前
机器视觉中光源镜头和相机的关系
数码相机·相机·机器视觉·光源·镜头
博图光电5 天前
UV紫外相机
数码相机·uv·紫外相机
OCR_wintone4215 天前
易泊车牌识别相机:夜间识别的卓越之选
大数据·人工智能·数码相机·ocr
随风19875 天前
相机硬触发
数码相机
吃个糖糖6 天前
Halcon 3D平面相切案例
数码相机·平面·3d
越甲八千6 天前
单个相机矫正畸变
数码相机