最近遇到一个客户需求,要求在前摄的时候,不要求镜像预览,拍出来的照片也不要求镜像。
科谱一下,前摄镜像的原因是让镜头对着自己,当镜子使用,是专门这么设计的。
既然客户有要求,那就得修改了。
通过各种渠道找,之前想通过驱动层在这里插入代码片
修改代码, 但是驱动同事告诉我,预览可以修改,拍出来的照片修改不了。
拍出来 的照片只能是在应用层修改,那就只能在AP侧找源码。
此代码是基于高通的基础之上的,android 7.1平台。
packages\apps\SnapdragonCamera\src\com\android\camera\PhotoModule.java
private void setFlipValue() {
// Read Flip mode from adb command
//value: 0(default) - FLIP_MODE_OFF
//value: 1 - FLIP_MODE_H
//value: 2 - FLIP_MODE_V
//value: 3 - FLIP_MODE_VH
int preview_flip_value = SystemProperties.getInt("debug.camera.preview.flip", 0);
int video_flip_value = SystemProperties.getInt("debug.camera.video.flip", 0);
int picture_flip_value = SystemProperties.getInt("debug.camera.picture.flip", 0);
int rotation = CameraUtil.getJpegRotation(mCameraId, mOrientation);
mParameters.setRotation(rotation);
if (rotation == 90 || rotation == 270) {
// in case of 90 or 270 degree, V/H flip should reverse
if (preview_flip_value == 1) {
preview_flip_value = 2;
} else if (preview_flip_value == 2) {
preview_flip_value = 1;
}
if (video_flip_value == 1) {
video_flip_value = 2;
} else if (video_flip_value == 2) {
video_flip_value = 1;
}
if (picture_flip_value == 1) {
picture_flip_value = 2;
} else if (picture_flip_value == 2) {
picture_flip_value = 1;
}
}
String preview_flip = CameraUtil.getFilpModeString(preview_flip_value);
String video_flip = CameraUtil.getFilpModeString(video_flip_value);
String picture_flip = CameraUtil.getFilpModeString(picture_flip_value);
if(CameraUtil.isSupported(preview_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_PREVIEW_FLIP, preview_flip);
}
if(CameraUtil.isSupported(video_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_VIDEO_FLIP, video_flip);
}
if(CameraUtil.isSupported(picture_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_SNAPSHOT_PICTURE_FLIP, picture_flip);
}
}
找到这个函数,
添加log,
private void setFlipValue() {
// Read Flip mode from adb command
//value: 0(default) - FLIP_MODE_OFF
//value: 1 - FLIP_MODE_H
//value: 2 - FLIP_MODE_V
//value: 3 - FLIP_MODE_VH
int preview_flip_value = SystemProperties.getInt("debug.camera.preview.flip", 0);
int video_flip_value = SystemProperties.getInt("debug.camera.video.flip", 0);
int picture_flip_value = SystemProperties.getInt("debug.camera.picture.flip", 0);
int rotation = CameraUtil.getJpegRotation(mCameraId, mOrientation);
Log.d("leo","preview_flip_value-->"+preview_flip_value);
Log.d("leo","video_flip_value-->"+video_flip_value);
Log.d("leo","picture_flip_value-->"+picture_flip_value);
Log.d("leo","rotation-->"+rotation);
Log.d("leo","mCameraId-->"+mCameraId);
Log.d("leo","mOrientation-->"+mOrientation);
mParameters.setRotation(rotation);
if (rotation == 90 || rotation == 270) {
// in case of 90 or 270 degree, V/H flip should reverse
if (preview_flip_value == 1) {
preview_flip_value = 2;
} else if (preview_flip_value == 2) {
preview_flip_value = 1;
}
if (video_flip_value == 1) {
video_flip_value = 2;
} else if (video_flip_value == 2) {
video_flip_value = 1;
}
if (picture_flip_value == 1) {
picture_flip_value = 2;
} else if (picture_flip_value == 2) {
picture_flip_value = 1;
}
}
String preview_flip = CameraUtil.getFilpModeString(preview_flip_value);
String video_flip = CameraUtil.getFilpModeString(video_flip_value);
String picture_flip = CameraUtil.getFilpModeString(picture_flip_value);
Log.d("leo","preview_flip-->"+preview_flip);
Log.d("leo","video_flip-->"+video_flip);
Log.d("leo","picture_flip-->"+picture_flip);
if(CameraUtil.isSupported(preview_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_PREVIEW_FLIP, preview_flip);
}
if(CameraUtil.isSupported(video_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_VIDEO_FLIP, video_flip);
}
if(CameraUtil.isSupported(picture_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_SNAPSHOT_PICTURE_FLIP, picture_flip);
}
}
在代码的这个地方,
mParameters.set
设置相机的属性时,会有一个flip属性,这个属性就可以设置拍出来的照片是否镜像,v方向还是h方向镜像。
如果需要修改,可以参考以下:
private void setFlipValue() {
// Read Flip mode from adb command
//value: 0(default) - FLIP_MODE_OFF
//value: 1 - FLIP_MODE_H
//value: 2 - FLIP_MODE_V
//value: 3 - FLIP_MODE_VH
int preview_flip_value = SystemProperties.getInt("debug.camera.preview.flip", 0);
int video_flip_value = SystemProperties.getInt("debug.camera.video.flip", 0);
int picture_flip_value = SystemProperties.getInt("debug.camera.picture.flip", 0);
int rotation = CameraUtil.getJpegRotation(mCameraId, mOrientation);
Log.d("leo","preview_flip_value-->"+preview_flip_value);
Log.d("leo","video_flip_value-->"+video_flip_value);
Log.d("leo","picture_flip_value-->"+picture_flip_value);
Log.d("leo","rotation-->"+rotation);
Log.d("leo","mCameraId-->"+mCameraId);
Log.d("leo","mOrientation-->"+mOrientation);
// 在这个地方添加对cameraiId的判断,也就是你想镜像哪一个camera,就判断一个id就可以了,
// 对filp的修改也是根据你的需要来修改的,我这里只需要修改拍照后的镜像,那就修改picture_flip_value
if(2 == mCameraId){
picture_flip_value = 2;
}
mParameters.setRotation(rotation);
if (rotation == 90 || rotation == 270) {
// in case of 90 or 270 degree, V/H flip should reverse
if (preview_flip_value == 1) {
preview_flip_value = 2;
} else if (preview_flip_value == 2) {
preview_flip_value = 1;
}
if (video_flip_value == 1) {
video_flip_value = 2;
} else if (video_flip_value == 2) {
video_flip_value = 1;
}
if (picture_flip_value == 1) {
picture_flip_value = 2;
} else if (picture_flip_value == 2) {
picture_flip_value = 1;
}
}
String preview_flip = CameraUtil.getFilpModeString(preview_flip_value);
String video_flip = CameraUtil.getFilpModeString(video_flip_value);
String picture_flip = CameraUtil.getFilpModeString(picture_flip_value);
Log.d("leo","preview_flip-->"+preview_flip);
Log.d("leo","video_flip-->"+video_flip);
Log.d("leo","picture_flip-->"+picture_flip);
if(CameraUtil.isSupported(preview_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_PREVIEW_FLIP, preview_flip);
}
if(CameraUtil.isSupported(video_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_VIDEO_FLIP, video_flip);
}
if(CameraUtil.isSupported(picture_flip, CameraSettings.getSupportedFlipMode(mParameters))){
mParameters.set(CameraSettings.KEY_QC_SNAPSHOT_PICTURE_FLIP, picture_flip);
}
}