当前位置: 首页>>代码示例>>Java>>正文


Java Camera.getCameraInfo方法代码示例

本文整理汇总了Java中android.hardware.Camera.getCameraInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Camera.getCameraInfo方法的具体用法?Java Camera.getCameraInfo怎么用?Java Camera.getCameraInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.Camera的用法示例。


在下文中一共展示了Camera.getCameraInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openCamera

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public void openCamera() {
    Camera.CameraInfo info = new Camera.CameraInfo();

    // Try to find a front-facing camera (e.g. for videoconferencing).
    int numCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numCameras; i++) {
        Camera.getCameraInfo(i, info);
        if (info.facing == currentCamera) {
            camera = Camera.open(i);
            break;
        }
    }
    if (camera == null) {
        camera = Camera.open();
    }

    Camera.Parameters parms = camera.getParameters();

    CameraUtils.choosePreviewSize(parms, previewWidth, previewHeight);
    isOpened = true;
}
 
开发者ID:ChillingVan,项目名称:AndroidInstantVideo,代码行数:23,代码来源:InstantVideoCamera.java

示例2: determineCameraId

import android.hardware.Camera; //导入方法依赖的package包/类
private int determineCameraId() {
    final int cameraCount = Camera.getNumberOfCameras();
    final CameraInfo cameraInfo = new CameraInfo();

    // prefer back-facing camera
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
            return i;
    }

    // fall back to front-facing camera
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
            return i;
    }

    return -1;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:CameraManager.java

示例3: onCreate

import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a container that will hold a SurfaceView for camera previews
    mPreview = new Preview(this.getActivity());

    // Find the total number of cameras available
    mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the rear-facing ("default") camera
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            mCurrentCamera = mDefaultCameraId = i;
        }
    }
    setHasOptionsMenu(mNumberOfCameras > 1);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:21,代码来源:CameraFragment.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: 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) getContext().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:angcyo,项目名称:RLibrary,代码行数:33,代码来源:RCameraPreview.java

示例6: getIdForRequestedCamera

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Gets the id for the camera specified by the direction it is facing.  Returns -1 if no such
 * camera was found.
 *
 * @param facing the desired camera (front-facing or rear-facing)
 */
private static int getIdForRequestedCamera(int facing) {
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == facing) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:Jugendhackt,项目名称:SocialPaka,代码行数:17,代码来源:CameraSource.java

示例7: findCameraId

import android.hardware.Camera; //导入方法依赖的package包/类
public static int findCameraId(boolean front) {
    final Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    final int cameraCount = Camera.getNumberOfCameras();
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if ((front&&cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) || (!front&&cameraInfo.facing==Camera.CameraInfo.CAMERA_FACING_BACK)) {
            return i;
        }
    }
    return CameraConfig.NO_CAMERA;
}
 
开发者ID:zhouzhuo810,项目名称:CameraCardCropDemo,代码行数:12,代码来源:CameraUtils.java

示例8: getCameraId

import android.hardware.Camera; //导入方法依赖的package包/类
private int getCameraId() {
  CameraInfo ci = new CameraInfo();
  for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
    Camera.getCameraInfo(i, ci);
    if (ci.facing == CameraInfo.CAMERA_FACING_BACK)
      return i;
  }
  return -1; // No camera found
}
 
开发者ID:Nilhcem,项目名称:tensorflow-classifier-android,代码行数:10,代码来源:LegacyCameraConnectionFragment.java

示例9: GetCameraInfo

import android.hardware.Camera; //导入方法依赖的package包/类
public static PjCameraInfo GetCameraInfo(int idx)
   {
if (idx < 0 || idx >= GetCameraCount())
    return null;

Camera cam;
try {
    cam = Camera.open(idx);
} catch (Exception e) {
    Log.d("IOException", e.getMessage());
    return null;
}

PjCameraInfo pjci = new PjCameraInfo();

Camera.CameraInfo ci = new Camera.CameraInfo();
Camera.getCameraInfo(idx, ci);

pjci.facing = ci.facing;
pjci.orient = ci.orientation;

Camera.Parameters param = cam.getParameters();
cam.release();
cam = null;

pjci.supportedFormat = IntegerListToIntArray(
			    param.getSupportedPreviewFormats());
pjci.supportedFps1000 = IntArrayListToIntArray(
			    param.getSupportedPreviewFpsRange());
pjci.supportedSize = CameraSizeListToIntArray(
			    param.getSupportedPreviewSizes());

return pjci;
   }
 
开发者ID:aksalj,项目名称:africastalking-android,代码行数:35,代码来源:PjCameraInfo.java

示例10: isCameraExist

import android.hardware.Camera; //导入方法依赖的package包/类
public static boolean isCameraExist(int cameraId) {
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == cameraId) {
            return true;
        }
    }
    return false;
}
 
开发者ID:imjaspreet,项目名称:Camera-Background-Servce,代码行数:12,代码来源:Util.java

示例11: setRotation

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Calculates the correct rotation for the given camera id and sets the rotation in the
 * parameters.  It also sets the camera's display orientation and rotation.
 *
 * @param parameters the camera parameters for which to set the rotation
 * @param cameraId   the camera id to set rotation based on
 */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager =
            (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    int rotation = windowManager.getDefaultDisplay().getRotation();
    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;
        default:
            Log.e(TAG, "Bad rotation value: " + rotation);
    }

    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int angle;
    int displayAngle;
    if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        displayAngle = (360 - angle); // compensate for it being mirrored
    } else {  // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }

    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;

    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
 
开发者ID:Jugendhackt,项目名称:SocialPaka,代码行数:49,代码来源:CameraSource.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 means
 *            "no preference"
 * @return handle to {@link Camera} that was opened
 */
public static Camera open(int cameraId) {

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

	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;
	}

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

	return camera;
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:50,代码来源:OpenCameraInterface.java

示例13: openCamera

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens a camera, and attempts to establish preview mode at the specified width
 * and height with a fixed frame rate.
 * <p>
 * Sets mCameraPreviewWidth / mCameraPreviewHeight.
 */
private void openCamera(int desiredWidth, int desiredHeight, int desiredFps) {
    if (mCamera != null) {
        throw new RuntimeException("camera already initialized");
    }

    Camera.CameraInfo info = new Camera.CameraInfo();

    // Try to find a front-facing camera (e.g. for videoconferencing).
    int numCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numCameras; i++) {
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            mCamera = Camera.open(i);
            break;
        }
    }
    if (mCamera == null) {
        Log.d(TAG, "No front-facing camera found; opening default");
        mCamera = Camera.open();    // opens first back-facing camera
    }
    if (mCamera == null) {
        throw new RuntimeException("Unable to open camera");
    }

    Camera.Parameters parms = mCamera.getParameters();

    CameraUtils.choosePreviewSize(parms, desiredWidth, desiredHeight);

    // Try to set the frame rate to a constant value.
    int thousandFps = CameraUtils.chooseFixedPreviewFps(parms, desiredFps * 1000);

    // Give the camera a hint that we're recording video.  This can have a big
    // impact on frame rate.
    parms.setRecordingHint(true);

    mCamera.setParameters(parms);

    int[] fpsRange = new int[2];
    Camera.Size mCameraPreviewSize = parms.getPreviewSize();
    parms.getPreviewFpsRange(fpsRange);
    String previewFacts = mCameraPreviewSize.width + "x" + mCameraPreviewSize.height;
    if (fpsRange[0] == fpsRange[1]) {
        previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps";
    } else {
        previewFacts += " @[" + (fpsRange[0] / 1000.0) +
                " - " + (fpsRange[1] / 1000.0) + "] fps";
    }
    Log.i(TAG, "Camera config: " + previewFacts);

    mCameraPreviewWidth = mCameraPreviewSize.width;
    mCameraPreviewHeight = mCameraPreviewSize.height;
    mMainHandler.sendCameraParams(mCameraPreviewWidth, mCameraPreviewHeight,
            thousandFps / 1000.0f);
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:61,代码来源:TextureFromCameraActivity.java

示例14: openCamera

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens a camera, and attempts to establish preview mode at the specified width and height.
 * <p>
 * Sets mCameraPreviewWidth and mCameraPreviewHeight to the actual width/height of the preview.
 */
private void openCamera(int desiredWidth, int desiredHeight) {
    if (mCamera != null) {
        throw new RuntimeException("camera already initialized");
    }

    Camera.CameraInfo info = new Camera.CameraInfo();

    // Try to find a front-facing camera (e.g. for videoconferencing).
    int numCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numCameras; i++) {
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            mCamera = Camera.open(i);
            break;
        }
    }
    if (mCamera == null) {
        Log.d(TAG, "No front-facing camera found; opening default");
        mCamera = Camera.open();    // opens first back-facing camera
    }
    if (mCamera == null) {
        throw new RuntimeException("Unable to open camera");
    }

    Camera.Parameters parms = mCamera.getParameters();

    CameraUtils.choosePreviewSize(parms, desiredWidth, desiredHeight);

    // Give the camera a hint that we're recording video.  This can have a big
    // impact on frame rate.
    parms.setRecordingHint(true);

    // leave the frame rate set to default
    mCamera.setParameters(parms);

    int[] fpsRange = new int[2];
    Camera.Size mCameraPreviewSize = parms.getPreviewSize();
    parms.getPreviewFpsRange(fpsRange);
    String previewFacts = mCameraPreviewSize.width + "x" + mCameraPreviewSize.height;
    if (fpsRange[0] == fpsRange[1]) {
        previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps";
    } else {
        previewFacts += " @[" + (fpsRange[0] / 1000.0) +
                " - " + (fpsRange[1] / 1000.0) + "] fps";
    }
    TextView text = (TextView) findViewById(R.id.cameraParams_text);
    text.setText(previewFacts);

    mCameraPreviewWidth = mCameraPreviewSize.width;
    mCameraPreviewHeight = mCameraPreviewSize.height;
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:57,代码来源:CameraCaptureActivity.java

示例15: 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 means
 *                 "no preference"
 * @return handle to {@link Camera} that was opened
 */
public static Camera open(int cameraId) {

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

    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;
    }

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

    return camera;
}
 
开发者ID:Hultron,项目名称:LifeHelper,代码行数:49,代码来源:OpenCameraInterface.java


注:本文中的android.hardware.Camera.getCameraInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。