List of usage examples for android.hardware Camera getCameraInfo
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo)
From source file:com.arthurtimberly.fragments.CaptureFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*//from ww w. jav a 2s .co m * Get params. */ Bundle args = getArguments(); mUseFrontFacing = args.getBoolean(FRAGMENT_BUNDLE_KEY_CAMERA); /* * Default to first camera available. */ mNumCameras = Camera.getNumberOfCameras(); if (mNumCameras > 0) { mCameraId = 0; } /* * Try to select camera based on preference. */ int cameraPreference = CameraInfo.CAMERA_FACING_BACK; if (mUseFrontFacing) { cameraPreference = CameraInfo.CAMERA_FACING_FRONT; } CameraInfo cameraInfo = new CameraInfo(); for (int cameraId = 0; cameraId < mNumCameras; cameraId++) { Camera.getCameraInfo(cameraId, cameraInfo); // Set flag to indicate whether the camera image is reflected. mIsReflected = isCameraImageReflected(cameraInfo); // Break on finding the preferred camera. if (cameraInfo.facing == cameraPreference) { mCameraId = cameraId; break; } } }
From source file:org.artoolkit.ar.samples.nftBook.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override/*from w w w .jav a 2s . c om*/ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); nftBookActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:org.artoolkit.ar.samples.ARNativeES1.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override// w ww . j av a2 s . c o m public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); ARNativeES1Activity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:org.artoolkit.ar.samples.ARNativeOSG.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override// w ww . j ava 2s .c om public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); ARNativeOSGActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:com.mobiuso.argo.ARModule.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override/*from w w w . ja va 2s . c om*/ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); ARMovieActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:org.artoolkit.ar.samples.ARNative.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override// ww w .j a v a2s .c o m public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); ARNativeActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:com.google.android.cameraview.Camera1.java
/** * This rewrites {@link #mCameraId} and {@link #mCameraInfo}. *///from ww w .j a va 2 s. com private void chooseCamera() { for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) { Camera.getCameraInfo(i, mCameraInfo); if (mCameraInfo.facing == mFacing) { mCameraId = i; return; } } mCameraId = INVALID_CAMERA_ID; }
From source file:uk.ac.horizon.artcodes.camera.CameraView.java
private void openCamera(int cameraId) { Log.i("Scanner", "Device manufacturer: " + android.os.Build.MANUFACTURER + " model: " + android.os.Build.MODEL); camera = Camera.open(cameraId);//from ww w.j a va 2s . c om Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); Camera.Parameters parameters = camera.getParameters(); List<String> focusModes = parameters.getSupportedFocusModes(); if (//!android.os.Build.MANUFACTURER.equalsIgnoreCase("SAMSUNG") && focusModes != null && !(this.experience != null && this.experience.getRequestedAutoFocusMode() != null && (this.experience.getRequestedAutoFocusMode().equals("tapToFocus") || this.experience.getRequestedAutoFocusMode().equals("blurScore")) && focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) && focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } else if (focusModes != null && focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { // if FOCUS_MODE_CONTINUOUS_VIDEO is not supported flag that manual auto-focus is needed every few seconds Log.w("Scanner", "Camera requires manual focusing"); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); if (!(this.experience.getRequestedAutoFocusMode() != null && this.experience.getRequestedAutoFocusMode().equals("blurScore"))) { deviceNeedsTapToFocus = true; } } float ratioOfSurface = (float) surfaceHeight / surfaceWidth; if (ratioOfSurface < 1) { ratioOfSurface = 1 / ratioOfSurface; } Log.i("Scanner", "Surface size: " + surfaceWidth + "x" + surfaceHeight + " (Ratio: " + ratioOfSurface + ")"); Log.i("Scanner", "Format = " + parameters.getPictureFormat()); // Step 2: Find scanner preview that is best match for estimated surface ratio final List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes(); Camera.Size bestFitSoFar = null; float ratioDifferenceOfBestFitSoFar = 0; StringBuilder cameraPreviewSizeDebugMessage = new StringBuilder("Available camera preview sizes: "); for (Camera.Size supportedSize : supportedPreviewSizes) { float ratio = (float) supportedSize.width / supportedSize.height; float ratioDifference = Math.abs(ratio - ratioOfSurface); cameraPreviewSizeDebugMessage.append(supportedSize.width); cameraPreviewSizeDebugMessage.append('x'); cameraPreviewSizeDebugMessage.append(supportedSize.height); cameraPreviewSizeDebugMessage.append(" ("); cameraPreviewSizeDebugMessage.append(ratio); cameraPreviewSizeDebugMessage.append(") "); if (bestFitSoFar == null || ratioDifference < ratioDifferenceOfBestFitSoFar) { bestFitSoFar = supportedSize; ratioDifferenceOfBestFitSoFar = ratioDifference; } } Log.i("Scanner", cameraPreviewSizeDebugMessage.toString()); if (bestFitSoFar != null) { // Would only be null if there are no supportedPreviewSizes this.debug_resolution = "Selected Preview Size: " + bestFitSoFar.width + "x" + bestFitSoFar.height + " (" + ((float) bestFitSoFar.width / (float) bestFitSoFar.height) + ")"; Log.i("Scanner", this.debug_resolution); parameters.setPreviewSize(bestFitSoFar.width, bestFitSoFar.height); camera.setParameters(parameters); info = new CameraInfo(cameraInfo, parameters, getDeviceRotation()); camera.setDisplayOrientation(info.getRotation()); setDetector(detector, experience); try { camera.setPreviewDisplay(surface); } catch (IOException e) { Log.w("Scanner", e.getMessage(), e); } camera.startPreview(); } }
From source file:org.artoolkit.ar.samples.nftSimple.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override/* w ww. j a v a 2 s. c om*/ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); nftSimpleActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }
From source file:org.artoolkit.ar.utils.calib_optical.CameraSurface.java
@SuppressLint("NewApi") // CameraInfo @SuppressWarnings("deprecation") // setPreviewFrameRate @Override/* w w w .ja v a 2 s . c o m*/ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera != null) { String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); int capWidth = parameters.getPreviewSize().width; int capHeight = parameters.getPreviewSize().height; int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean frontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; } int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]); camera.startPreview(); calib_optical_Activity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing); } }