Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 如何實現前置camera自拍鏡像功能

android 如何實現前置camera自拍鏡像功能

編輯:關於Android編程

默認的前置camera, 文字”XI”在preview時顯示為”IX”(前置camera preview時默認會有mirror效果), 拍攝出來的照片為"XI",如何讓拍攝出來的照片也是”IX” , 也就是和preview時保持一致?



對於普通單拍(非ZSD或其他拍照模式), 需要修改的代碼為normalShot.cpp文件中的onCmd_capture()方法,
將原來的
bool
NormalShot::
onCmd_capture()
{
AutoCPTLog cptlog(Event_Shot_capture);
MBOOL ret = MTRUE;
NSCamShot::ISingleShot *pSingleShot = NSCamShot::ISingleShot::createInstance(static_cast(mu4ShotMode), "NormalShot");
......

// shot param
NSCamShot::ShotParam rShotParam(eImgFmt_YUY2, //yuv format
mShotParam.mi4PictureWidth, //picutre width
mShotParam.mi4PictureHeight, //picture height
mShotParam.mi4Rotation, //picture rotation
0, //picture flip
ePostViewFmt, // postview format
mShotParam.mi4PostviewWidth, //postview width
mShotParam.mi4PostviewHeight, //postview height
0, //postview rotation
0, //postview flip
mShotParam.mu4ZoomRatio //zoom
);

......
}

修改為:
bool
NormalShot::
onCmd_capture()
{
AutoCPTLog cptlog(Event_Shot_capture);
MBOOL ret = MTRUE;
NSCamShot::ISingleShot *pSingleShot = NSCamShot::ISingleShot::createInstance(static_cast(mu4ShotMode), "NormalShot");
......

// shot param
NSCamShot::ShotParam rShotParam(eImgFmt_YUY2, //yuv format
mShotParam.mi4PictureWidth, //picutre width
mShotParam.mi4PictureHeight, //picture height
mShotParam.mi4Rotation, //picture rotation
(getOpenId()==1? 1:0), //picture flip //此處為修改的代碼,將這裡的值改為1,底層則會將image做橫向的flip, 相當於mirror.
ePostViewFmt, // postview format
mShotParam.mi4PostviewWidth, //postview width
mShotParam.mi4PostviewHeight, //postview height
0, //postview rotation
0, //postview flip
mShotParam.mu4ZoomRatio //zoom
);

......
}

主要將參數rShotParam裡面的flip值改為1, 值為1表示底層將把image做橫向的flip,若為0則不做.
(上述改動中的getOpenId()==1? 1:0只為測試使用,意為判斷當前是否為前置camera, 若為前置camera, 則賦值為1)
請您注意:
在實際應用中, 請在Parameters中新增一個Flip參數, 並在app中通過Parameters傳遞Flip值到HAL層來通知底層做flip. (為避免影響CTS測試和三方應用, 請勿直接將上述的提到的flip值固定寫為1.)
涉及修改的文件主要如下:
NormalShot.cpp (mediatek\platform\mt6589\hardware\camera\hal\adapter\scenario\shot\normalshot)
IShot.h (mediatek\platform\mt6589\hardware\camera\hal\adapter\inc\scenario\shot)
CameraParameters.cpp (frameworks\av\camera)
CameraParameters.h (frameworks\av\include\camera)
ParamsManager.update.cpp (mediatek\hardware\camera\common\paramsmgr\params)
MtkPhotoCamAdapter.Capture.cpp (mediatek\platform\mt6589\hardware\camera\hal\adapter\mtkphoto)
Camera.java(\frameworks\base\core\java\android\hardware\)
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved