當前位置: 首頁>>代碼示例>>Java>>正文


Java Camera.CameraInfo方法代碼示例

本文整理匯總了Java中android.hardware.Camera.CameraInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java Camera.CameraInfo方法的具體用法?Java Camera.CameraInfo怎麽用?Java Camera.CameraInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.hardware.Camera的用法示例。


在下文中一共展示了Camera.CameraInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCurrentCamera

import android.hardware.Camera; //導入方法依賴的package包/類
/**
 * Returns current camera identifier.
 *
 * @return Camera id.
 */
private int getCurrentCamera() {
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    int cameraCount = Camera.getNumberOfCameras();
    for(int camIdx = 0; camIdx < cameraCount; camIdx++) {
        Camera.getCameraInfo(camIdx, cameraInfo);
        if(mFrontCamera && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            logi("returning front camera");
            return camIdx;
        } else if(!mFrontCamera && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            logi("returning back camera");
            return camIdx;
        }

    }
    return -1;
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:22,代碼來源:CameraActivity_OldAPI.java

示例2: configureRecorder

import android.hardware.Camera; //導入方法依賴的package包/類
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);
    recorder.setOrientationHint(displayOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:19,代碼來源:CameraSession.java

示例3: CameraPreview

import android.hardware.Camera; //導入方法依賴的package包/類
public CameraPreview(Context context, Camera camera, Camera.CameraInfo cameraInfo,
                     int displayOrientation) {
    super(context);

    // Do not initialise if no camera has been set
    if (camera == null || cameraInfo == null) {
        return;
    }
    mCamera = camera;
    mCameraInfo = cameraInfo;
    mDisplayOrientation = displayOrientation;

    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = getHolder();
    mHolder.addCallback(this);
}
 
開發者ID:GeekyShiva,項目名稱:Self-Driving-Car,代碼行數:18,代碼來源:CameraPreview.java

示例4: setDefaultCameraId

import android.hardware.Camera; //導入方法依賴的package包/類
private void setDefaultCameraId(){
  // Find the total number of cameras available
  numberOfCameras = Camera.getNumberOfCameras();

  int camId = defaultCamera.equals("front") ? Camera.CameraInfo.CAMERA_FACING_FRONT : Camera.CameraInfo.CAMERA_FACING_BACK;

  // Find the ID of the default camera
  Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
  for (int i = 0; i < numberOfCameras; i++) {
    Camera.getCameraInfo(i, cameraInfo);
    if (cameraInfo.facing == camId) {
      defaultCameraId = camId;
      break;
    }
  }
}
 
開發者ID:MrShakes,項目名稱:cameraPreviewStream,代碼行數:17,代碼來源:CameraActivity.java

示例5: CameraManager

import android.hardware.Camera; //導入方法依賴的package包/類
private CameraManager() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        mCameraInfoHashMap.put(i, info);

        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            mTypeToIndex.put(TYPE_CAMERA_BACK, i);
        } else {
            mTypeToIndex.put(TYPE_CAMERA_FRONT, i);
        }
    }
}
 
開發者ID:cuonghuynhvan,項目名稱:react-native-camera-android-simple,代碼行數:14,代碼來源:CameraManager.java

示例6: getDisplayOrientation

import android.hardware.Camera; //導入方法依賴的package包/類
public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    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;
    } else {
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}
 
開發者ID:RuanXiaoHui,項目名稱:ZxingScan,代碼行數:33,代碼來源:CameraConfigurationManager.java

示例7: getCameraId

import android.hardware.Camera; //導入方法依賴的package包/類
public static int getCameraId(int requestedId) {
    int numCameras = Camera.getNumberOfCameras();
    if (numCameras == 0) {
        Log.w(TAG, "No cameras!");
        return -1;
    }

    int cameraId = requestedId;

    boolean explicitRequest = cameraId >= 0;

    if (!explicitRequest) {
        // Select a camera if no explicit camera requested
        int index = 0;
        while (index < numCameras) {
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            Camera.getCameraInfo(index, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                break;
            }
            index++;
        }

        cameraId = index;
    }

    if (cameraId < numCameras) {
        return cameraId;
    } else {
        if (explicitRequest) {
            return -1;
        } else {
            return 0;
        }
    }
}
 
開發者ID:yinhaojun,項目名稱:ZxingForAndroid,代碼行數:37,代碼來源:OpenCameraInterface.java

示例8: startCamera

import android.hardware.Camera; //導入方法依賴的package包/類
/**
 * 打開指定攝像頭開始預覽,但是並未開始識別
 *
 * @param cameraFacing
 */
public void startCamera(int cameraFacing) {
    if (mCamera != null) {
        return;
    }
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int cameraId = 0; cameraId < Camera.getNumberOfCameras(); cameraId++) {
        Camera.getCameraInfo(cameraId, cameraInfo);
        if (cameraInfo.facing == cameraFacing) {
            startCameraById(cameraId);
            break;
        }
    }
}
 
開發者ID:devzwy,項目名稱:NeiHanDuanZiTV,代碼行數:19,代碼來源:QRCodeView.java

示例9: getDisplayOrientation

import android.hardware.Camera; //導入方法依賴的package包/類
public static int getDisplayOrientation(int degrees, Camera.CameraInfo info) {

    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;
    }
    return result;
  }
 
開發者ID:windwang,項目名稱:react-native-face-detect,代碼行數:12,代碼來源:Converter.java

示例10: getBackCamera

import android.hardware.Camera; //導入方法依賴的package包/類
private Pair<Camera.CameraInfo, Integer> getBackCamera() {
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    final int numberOfCameras = Camera.getNumberOfCameras();

    // Iterates through each camera and, if camera id is for back camera, returns its index and info
    for (int i = 0; i < numberOfCameras; ++i) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            return new Pair<Camera.CameraInfo, Integer>(cameraInfo,
                    Integer.valueOf(i));
        }
    }
    return null;
}
 
開發者ID:csarron,項目名稱:renderscript_examples,代碼行數:15,代碼來源:CameraHandler.java

示例11: DecoderWrapper

import android.hardware.Camera; //導入方法依賴的package包/類
public DecoderWrapper(@NonNull Camera camera, @NonNull Camera.CameraInfo cameraInfo, @NonNull Decoder decoder,
        @NonNull Point imageSize, @NonNull Point previewSize, @NonNull Point viewSize, int displayOrientation,
        boolean autoFocusSupported, boolean flashSupported) {
    mCamera = camera;
    mCameraInfo = cameraInfo;
    mDecoder = decoder;
    mImageSize = imageSize;
    mPreviewSize = previewSize;
    mViewSize = viewSize;
    mDisplayOrientation = displayOrientation;
    mReverseHorizontal = cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT;
    mAutoFocusSupported = autoFocusSupported;
    mFlashSupported = flashSupported;
}
 
開發者ID:yuriy-budiyev,項目名稱:code-scanner,代碼行數:15,代碼來源:DecoderWrapper.java

示例12: open

import android.hardware.Camera; //導入方法依賴的package包/類
/**
 * Opens the requested camera with {@link Camera#open(int)}, if one exists.
 *
 * @param cameraId camera ID of the camera to use. A negative value
 *                 or {@link #NO_REQUESTED_CAMERA} means "no preference", in which case a rear-facing
 *                 camera is returned if possible or else any camera
 * @return handle to {@link OpenCamera} that was opened
 */
public static OpenCamera open(int cameraId) {

    int numCameras = Camera.getNumberOfCameras();
    if (numCameras == 0) {
        Log.w(TAG, "No cameras!");
        return null;
    }

    boolean explicitRequest = cameraId >= 0;

    Camera.CameraInfo selectedCameraInfo = null;
    int index;
    if (explicitRequest) {
        index = cameraId;
        selectedCameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(index, selectedCameraInfo);
    } else {
        index = 0;
        while (index < numCameras) {
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            Camera.getCameraInfo(index, cameraInfo);
            CameraFacing reportedFacing = CameraFacing.values()[cameraInfo.facing];
            if (reportedFacing == CameraFacing.BACK) {
                selectedCameraInfo = cameraInfo;
                break;
            }
            index++;
        }
    }

    Camera camera;
    if (index < numCameras) {
        Log.i(TAG, "Opening camera #" + index);
        camera = Camera.open(index);
    } else {
        if (explicitRequest) {
            Log.w(TAG, "Requested camera does not exist: " + cameraId);
            camera = null;
        } else {
            Log.i(TAG, "No camera facing " + CameraFacing.BACK + "; returning camera #0");
            camera = Camera.open(0);
            selectedCameraInfo = new Camera.CameraInfo();
            Camera.getCameraInfo(0, selectedCameraInfo);
        }
    }

    if (camera == null) {
        return null;
    }
    return new OpenCamera(index,
            camera,
            CameraFacing.values()[selectedCameraInfo.facing],
            selectedCameraInfo.orientation);
}
 
開發者ID:xiong-it,項目名稱:ZXingAndroidExt,代碼行數:63,代碼來源:OpenCameraInterface.java

示例13: getCameraInfo

import android.hardware.Camera; //導入方法依賴的package包/類
private @NonNull CameraInfo getCameraInfo() {
  final CameraInfo info = new Camera.CameraInfo();
  Camera.getCameraInfo(cameraId, info);
  return info;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:6,代碼來源:CameraView.java

示例14: open

import android.hardware.Camera; //導入方法依賴的package包/類
/**
 * Opens the requested camera with {@link Camera#open(int)}, if one exists.
 *
 * @param cameraId camera ID of the camera to use. A negative value
 *  or {@link #NO_REQUESTED_CAMERA} means "no preference", in which case a rear-facing
 *  camera is returned if possible or else any camera
 * @return handle to {@link OpenCamera} that was opened
 */
public static OpenCamera open(int cameraId) {

  int numCameras = Camera.getNumberOfCameras();
  if (numCameras == 0) {
    Log.w(TAG, "No cameras!");
    return null;
  }

  boolean explicitRequest = cameraId >= 0;

  Camera.CameraInfo selectedCameraInfo = null;
  int index;
  if (explicitRequest) {
    index = cameraId;
    selectedCameraInfo = new Camera.CameraInfo();
    Camera.getCameraInfo(index, selectedCameraInfo);
  } else {
    index = 0;
    while (index < numCameras) {
      Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
      Camera.getCameraInfo(index, cameraInfo);
      CameraFacing reportedFacing = CameraFacing.values()[cameraInfo.facing];
      if (reportedFacing == CameraFacing.BACK) {
        selectedCameraInfo = cameraInfo;
        break;
      }
      index++;
    }
  }

  Camera camera;
  if (index < numCameras) {
    Log.i(TAG, "Opening camera #" + index);
    camera = Camera.open(index);
  } else {
    if (explicitRequest) {
      Log.w(TAG, "Requested camera does not exist: " + cameraId);
      camera = null;
    } else {
      Log.i(TAG, "No camera facing " + CameraFacing.BACK + "; returning camera #0");
      camera = Camera.open(0);
      selectedCameraInfo = new Camera.CameraInfo();
      Camera.getCameraInfo(0, selectedCameraInfo);
    }
  }

  if (camera == null) {
    return null;
  }
  return new OpenCamera(index,
                        camera,
                        CameraFacing.values()[selectedCameraInfo.facing],
                        selectedCameraInfo.orientation);
}
 
開發者ID:Zmingxu,項目名稱:ZxingScanner,代碼行數:63,代碼來源:OpenCameraInterface.java

示例15: switchCamara

import android.hardware.Camera; //導入方法依賴的package包/類
private void switchCamara() {
    //切換前後攝像頭
    int cameraCount = 0;
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();//得到攝像頭的個數

    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);//得到每一個攝像頭的信息
        if (cameraPosition == 1) {
            //現在是後置,變更為前置
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {//代表攝像頭的方位,CAMERA_FACING_FRONT前置      CAMERA_FACING_BACK後置
                if (surfaceView != null && surfaceView.getHolder() != null && previewCallBack != null) {
                    surfaceView.getHolder().removeCallback(previewCallBack);
                }
                mCamera.setPreviewCallback(null);
                mCamera.stopPreview();//停掉原來攝像頭的預覽
                mCamera.lock();
                mCamera.release();//釋放資源
                mCamera = null;//取消原來攝像頭
                mCamera = Camera.open(i);//打開當前選中的攝像頭
               /* try {
                    if (null != mholder)
                        mCamera.setPreviewDisplay(mholder);//通過surfaceview顯示取景畫麵
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mCamera.startPreview();//開始預覽*/
                if (null != mholder)
                    setParams(mholder, Camera.CameraInfo.CAMERA_FACING_BACK);
                cameraPosition = 0;
                break;
            }
        } else {
            //現在是前置, 變更為後置
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {//代表攝像頭的方位,CAMERA_FACING_FRONT前置      CAMERA_FACING_BACK後置
                if (surfaceView != null && surfaceView.getHolder() != null && previewCallBack != null) {
                    surfaceView.getHolder().removeCallback(previewCallBack);
                }
                mCamera.setPreviewCallback(null);
                mCamera.stopPreview();//停掉原來攝像頭的預覽
                mCamera.lock();
                mCamera.release();//釋放資源
                mCamera = null;//取消原來攝像頭
                mCamera = Camera.open(i);//打開當前選中的攝像頭
                /*try {
                    if (null != mholder)
                        mCamera.setPreviewDisplay(mholder);//通過surfaceview顯示取景畫麵
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mCamera.startPreview();//開始預覽*/
                if (null != mholder)
                    setParams(mholder, Camera.CameraInfo.CAMERA_FACING_FRONT);
                cameraPosition = 1;
                break;
            }
        }

    }
}
 
開發者ID:yzzslow0,項目名稱:Ec2m,代碼行數:63,代碼來源:CamaraActivity.java


注:本文中的android.hardware.Camera.CameraInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。