android调用camera时,可以自己写一个activity,赋上相关参数,打开前camera就可以了;


需要申请的permission,在AndroidManifest.xml中添加:

        

主要功能,打开前camera

private Camera openFrontFacingCameraGingerbread() {    int cameraCount = 0;    Camera cam = null;    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();    cameraCount = Camera.getNumberOfCameras();        for (int camIdx = 0; camIdx < cameraCount; camIdx++) {        Camera.getCameraInfo(camIdx, cameraInfo);        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {            try {                cam = Camera.open(camIdx);                mCurrentCamIndex = camIdx;            } catch (RuntimeException e) {                Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());            }        }    }    return cam;}

根据打开时的横竖屏方向来调整preview角度

//根据横竖屏自动调节preview方向,Starting from API level 14, this method can be called when preview is active.private static void setCameraDisplayOrientation(Activity activity,int cameraId, Camera camera) {       Camera.CameraInfo info = new Camera.CameraInfo();        Camera.getCameraInfo(cameraId, info);             int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();              //degrees  the angle that the picture will be rotated clockwise. Valid values are 0, 90, 180, and 270.        //The starting position is 0 (landscape).        int degrees = 0;       switch (rotation)        {              case Surface.ROTATION_0: degrees = 0; break;                    case Surface.ROTATION_90: degrees = 90; break;               case Surface.ROTATION_180: degrees = 180; break;            case Surface.ROTATION_270: degrees = 270; break;          }             int result;         if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)       {                   result = (info.orientation + degrees) % 360;                result = (360 - result) % 360;  // compensate the mirror          }        else        {         // back-facing                 result = (info.orientation - degrees + 360) % 360;          }            camera.setDisplayOrientation(result);  } 


本博文关联的源码下载: http://download.csdn.net/detail/changliangdoscript/7446287 

更多相关文章

  1. Android 电子罗盘--指南针(方向传感器的应用)
  2. 【转载】Android事件分发机制完全解析,带你从源码的角度彻底理解(
  3. 通過XML設置屏幕方向(android:screenOrientation)详解
  4. Android事件分发机制完全解析,带你从源码的角度彻底理解
  5. Android Studio App设置线性布局LinerLayout控件垂直/水平方向排
  6. android 传感器获取方向总结
  7. android修改重力感应方向
  8. [置顶] 从源码角度分析Android View的绘制机制(一)
  9. 从性能角度选购Adroid智能手机,双核、大屏与游戏的取舍

随机推荐

  1. 2011.06.29(2)——— android 完全退出
  2. Introduction to Model View Presenter o
  3. Android中的Environment.getExternalStor
  4. Android(安卓)进程生命周期(Process Life
  5. android http://dl-ssl.google.com/andro
  6. android am命令
  7. roboguice - Android上的依赖注入框架
  8. Notification用法,注意API版本,API大于11的
  9. 启动android后没有应用图标,找不到应用程
  10. android 系统裁剪