1. 程式人生 > >android 如何實現前置camera自拍映象功能

android 如何實現前置camera自拍映象功能

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

                預設的前置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<EShotMode>(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<EShotMode>(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\)           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述