android.hardware.Camera Java Examples
The following examples show how to use
android.hardware.Camera.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdvCamera.java From adv_camera with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int getPhotoRotation() { int rotation; int orientation = mPhotoAngle; Camera.CameraInfo info = new Camera.CameraInfo(); if (cameraFacing == 0) { Camera.getCameraInfo(0, info); } else { Camera.getCameraInfo(1, info); } if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { rotation = (info.orientation + orientation) % 360; } return rotation; }
Example #2
Source File: CameraSource.java From android-vision with Apache License 2.0 | 6 votes |
/** * Sets the flash mode. * * @param mode flash mode. * @return {@code true} if the flash mode is set, {@code false} otherwise * @see #getFlashMode() */ public boolean setFlashMode(@FlashMode String mode) { synchronized (cameraLock) { if (camera != null && mode != null) { Camera.Parameters parameters = camera.getParameters(); if (parameters.getSupportedFlashModes().contains(mode)) { parameters.setFlashMode(mode); camera.setParameters(parameters); flashMode = mode; return true; } } return false; } }
Example #3
Source File: FaceOverlapFragment.java From Fatigue-Detection with MIT License | 6 votes |
@SuppressLint("NewApi") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); nv21 = new byte[PREVIEW_WIDTH * PREVIEW_HEIGHT * 2]; this.setPreviewCallback(new PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { synchronized (nv21) { System.arraycopy(data, 0, nv21, 0, data.length); isNV21ready = true; } } }); return view; }
Example #4
Source File: CameraConfigurationManager.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); //图片拉伸 Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; // preview size is always something like 480*320, other 320*480 if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = getCameraResolution(parameters, screenResolutionForCamera); Log.d(TAG, "Camera resolution: " + screenResolution); }
Example #5
Source File: CameraManager.java From ZxingSupport with Apache License 2.0 | 6 votes |
public void setZoom(int zoom) { if (!isZoomSupported()){ Log.d("setZoom","false"); return; } try { Camera.Parameters params = mCamera.getParameters(); final int MAX = params.getMaxZoom(); if(MAX==0)return; int zoomValue = params.getZoom(); zoomValue += zoom; params.setZoom(zoomValue); mCamera.setParameters(params); }catch (Exception e){ Log.d(TAG,"变焦异常"); } }
Example #6
Source File: CameraPreview.java From cordova-plugin-camera-preview with MIT License | 6 votes |
private boolean getFlashMode(CallbackContext callbackContext) { if(this.hasCamera(callbackContext) == false){ return true; } Camera camera = fragment.getCamera(); Camera.Parameters params = camera.getParameters(); String flashMode = params.getFlashMode(); if (flashMode != null ) { callbackContext.success(flashMode); } else { callbackContext.error("FlashMode not supported"); } return true; }
Example #7
Source File: LiveVideoBroadcaster.java From LiveVideoBroadcaster with Apache License 2.0 | 6 votes |
public int getCameraDisplayOrientation() { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(currentCameraId, info); int rotation = context.getWindowManager().getDefaultDisplay() .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; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; }
Example #8
Source File: CameraController.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void startPreview(final CameraSession session) { if (session == null) { return; } threadPool.execute(new Runnable() { @SuppressLint("NewApi") @Override public void run() { Camera camera = session.cameraInfo.camera; try { if (camera == null) { camera = session.cameraInfo.camera = Camera.open(session.cameraInfo.cameraId); } camera.startPreview(); } catch (Exception e) { session.cameraInfo.camera = null; if (camera != null) { camera.release(); } FileLog.e(e); } } }); }
Example #9
Source File: VideoCaptureAndroid.java From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License | 6 votes |
public VideoCaptureAndroid(int id, long native_capturer) { this.id = id; this.native_capturer = native_capturer; this.info = new Camera.CameraInfo(); Camera.getCameraInfo(id, info); // Must be the last thing in the ctor since we pass a reference to |this|! final VideoCaptureAndroid self = this; orientationListener = new OrientationEventListener(GetContext()) { @Override public void onOrientationChanged(int degrees) { if (degrees == OrientationEventListener.ORIENTATION_UNKNOWN) { return; } if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { degrees = (info.orientation - degrees + 360) % 360; } else { // back-facing degrees = (info.orientation + degrees) % 360; } self.OnOrientationChanged(self.native_capturer, degrees); } }; // Don't add any code here; see the comment above |self| above! }
Example #10
Source File: CameraUtils.java From smartcoins-wallet with MIT License | 6 votes |
public static boolean isFlashSupported(Camera camera) { /* Credits: Top answer at http://stackoverflow.com/a/19599365/868173 */ if (camera != null) { Camera.Parameters parameters = camera.getParameters(); if (parameters.getFlashMode() == null) { return false; } List<String> supportedFlashModes = parameters.getSupportedFlashModes(); if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) { return false; } } else { return false; } return true; }
Example #11
Source File: CameraConfigurationUtils.java From FoodOrdering with Apache License 2.0 | 6 votes |
public static void setBestExposure(Camera.Parameters parameters, boolean lightOn) { int minExposure = parameters.getMinExposureCompensation(); int maxExposure = parameters.getMaxExposureCompensation(); float step = parameters.getExposureCompensationStep(); if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) { // Set low when light is on float targetCompensation = lightOn ? MIN_EXPOSURE_COMPENSATION : MAX_EXPOSURE_COMPENSATION; int compensationSteps = Math.round(targetCompensation / step); float actualCompensation = step * compensationSteps; // Clamp value: compensationSteps = Math.max( Math.min(compensationSteps, maxExposure), minExposure); if (parameters.getExposureCompensation() == compensationSteps) { Log.i(TAG, "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation); } else { Log.i(TAG, "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation); parameters.setExposureCompensation(compensationSteps); } } else { Log.i(TAG, "Camera does not support exposure compensation"); } }
Example #12
Source File: Camera2VideoFragment.java From LiveMultimedia with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView for Camera2VideoFragment"); View view = inflater.inflate(R.layout.fragment_camera2_video, container, false); if (mVideoPreviewFrame != null) { if (mCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 && mCurrentApiVersion <= Build.VERSION_CODES.KITKAT) { createVideoPreviewWindow(Camera.CameraInfo.CAMERA_FACING_BACK); } if (mCurrentApiVersion >= Build.VERSION_CODES.LOLLIPOP) { createVideoPreviewWindowEnhanced(); } } return view; }
Example #13
Source File: CameraEngine.java From In77Camera with MIT License | 6 votes |
public void requestZoom(double zoomValue){ Log.d(TAG, "requestZoom: "+zoomValue+" "+lastZoomValueRec+" "+lastZoomValue); synchronized (this) { if (camera != null) { Camera.Parameters p = camera.getParameters(); if(p.isZoomSupported()){ lastZoomValueRec +=zoomValue; lastZoomValueRec=Math.max(0,Math.min(lastZoomValueRec,1.0)); int curZoom= (int) (lastZoomValueRec*p.getMaxZoom()); if(Math.abs(curZoom-lastZoomValue)>=1){ lastZoomValue= curZoom; p.setZoom(lastZoomValue); } }else return; camera.setParameters(p); } } }
Example #14
Source File: FlashLightUtils.java From zone-sdk with MIT License | 6 votes |
public boolean turnOnFlashLight() { if (camera == null) { camera = Camera.open(); camera.startPreview(); Camera.Parameters parameter = camera.getParameters(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { parameter.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); } else { parameter.set("flash-mode", "torch"); } camera.setParameters(parameter); handler.removeCallbacksAndMessages(null); handler.postDelayed(new Runnable() { @Override public void run() { turnOffFlashLight(); } }, OFF_TIME); } return true; }
Example #15
Source File: CameraManager.java From green_android with GNU General Public License v3.0 | 6 votes |
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; }
Example #16
Source File: OffscreenCameraActivity.java From android-openGL-canvas with Apache License 2.0 | 6 votes |
private 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 == Camera.CameraInfo.CAMERA_FACING_FRONT) { mCamera = Camera.open(i); break; } } if (mCamera == null) { mCamera = Camera.open(); // opens first back-facing camera } Camera.Parameters parms = mCamera.getParameters(); CameraUtils.choosePreviewSize(parms, 1280, 720); }
Example #17
Source File: PreviewActivity.java From retroboy with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Force switch to landscape orientation setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Check which camera to use for (int i = 0, cameras = Camera.getNumberOfCameras(); i < cameras; i++) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { _cameraid = i; break; } } _surface = new GLSurfaceView(this); _surface.setEGLContextClientVersion(2); _renderer = new PreviewRenderer(this); _surface.setRenderer(_renderer); setContentView(_surface); }
Example #18
Source File: CameraSource.java From trust-wallet-android-source with GNU General Public License v3.0 | 5 votes |
public int doZoom(float scale) { synchronized (mCameraLock) { if (mCamera == null) { return 0; } int currentZoom = 0; int maxZoom; Camera.Parameters parameters = mCamera.getParameters(); if (!parameters.isZoomSupported()) { Log.w(TAG, "Zoom is not supported on this device"); return currentZoom; } maxZoom = parameters.getMaxZoom(); currentZoom = parameters.getZoom() + 1; float newZoom; if (scale > 1) { newZoom = currentZoom + scale * (maxZoom / 10); } else { newZoom = currentZoom * scale; } currentZoom = Math.round(newZoom) - 1; if (currentZoom < 0) { currentZoom = 0; } else if (currentZoom > maxZoom) { currentZoom = maxZoom; } parameters.setZoom(currentZoom); mCamera.setParameters(parameters); return currentZoom; } }
Example #19
Source File: CameraConfigurationUtils.java From SimplifyReader with Apache License 2.0 | 5 votes |
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) { List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges)); if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) { int[] suitableFPSRange = null; for (int[] fpsRange : supportedPreviewFpsRanges) { int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) { suitableFPSRange = fpsRange; break; } } if (suitableFPSRange == null) { Log.i(TAG, "No suitable FPS range?"); } else { int[] currentFpsRange = new int[2]; parameters.getPreviewFpsRange(currentFpsRange); if (Arrays.equals(currentFpsRange, suitableFPSRange)) { Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange)); } else { Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange)); parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } } } }
Example #20
Source File: CameraView.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private void setDisplayOrientation(int rotationDegrees) { int orientation; CameraInfo info = new CameraInfo(); Camera.getCameraInfo(0, info); if(info.facing == CAMERA_FACING_FRONT) { orientation = (info.orientation + rotationDegrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (info.orientation - rotationDegrees + 360) % 360; } camera.setDisplayOrientation(orientation); displayOrientation = orientation; }
Example #21
Source File: CameraSource.java From flutter_barcode_scanner with MIT License | 5 votes |
public SizePair(android.hardware.Camera.Size previewSize, android.hardware.Camera.Size pictureSize) { mPreview = new Size(previewSize.width, previewSize.height); if (pictureSize != null) { mPicture = new Size(pictureSize.width, pictureSize.height); } }
Example #22
Source File: CameraManager.java From DanDanPlayForAndroid with MIT License | 5 votes |
public void setPreviewCallback(Camera.PreviewCallback previewCallback) { this.previewCallback = previewCallback; if (isOpen()) { openCamera.getCamera().setPreviewCallback(previewCallback); } }
Example #23
Source File: AutoFocusCallback.java From QrModule with Apache License 2.0 | 5 votes |
public void onAutoFocus(boolean success, Camera camera) { if (autoFocusHandler != null) { Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success); autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS); autoFocusHandler = null; } else { Log.d(TAG, "Got auto-focus callback, but no handler for it"); } }
Example #24
Source File: CameraConfigurationUtils.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
public static void setFocusArea(Camera.Parameters parameters) { if (parameters.getMaxNumFocusAreas() > 0) { Log.i(TAG, "Old focus areas: " + toString(parameters.getFocusAreas())); List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000); Log.i(TAG, "Setting focus area to : " + toString(middleArea)); parameters.setFocusAreas(middleArea); } else { Log.i(TAG, "Device does not support focus areas"); } }
Example #25
Source File: LegacyCameraActions.java From Camera2 with Apache License 2.0 | 5 votes |
@Override public void executeOpen(SingleDeviceOpenListener<Camera> openListener, Lifetime deviceLifetime) throws UnsupportedOperationException { mLogger.i("executeOpen(id: " + mId.getCameraId() + ")"); mCameraHandler = mHandlerFactory.create(deviceLifetime, "LegacyCamera Handler"); mCameraHandler.post(new OpenCameraRunnable(openListener, mId.getCameraId().getLegacyValue(), mLogger)); }
Example #26
Source File: CameraFragment.java From androidtestdebug with MIT License | 5 votes |
public void setCamera(Camera camera) { mCamera = camera; if (mCamera != null) { mSupportedPreviewSizes = mCamera.getParameters() .getSupportedPreviewSizes(); requestLayout(); } }
Example #27
Source File: CameraImplV1.java From habpanelviewer with GNU General Public License v3.0 | 5 votes |
private Point[] toPointArray(List<Camera.Size> supportedPictureSizes) { ArrayList<Point> result = new ArrayList<>(); for (Camera.Size s : supportedPictureSizes) { result.add(new Point(s.width, s.height)); } return result.toArray(new Point[0]); }
Example #28
Source File: NativeCamera.java From LandscapeVideoCamera with Apache License 2.0 | 5 votes |
private int getCurrentCameraId() { int cameraId = -1; int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == getCurrentCameraFacing()) { cameraId = i; break; } } return cameraId; }
Example #29
Source File: CameraUtil.java From RxCamera with MIT License | 5 votes |
public static Camera.CameraInfo getCameraInfo(int id) { if (id >= 0 && id < getCameraNumber()) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(id, cameraInfo); return cameraInfo; } return null; }
Example #30
Source File: AutoFocusManager.java From qrcode_android with GNU Lesser General Public License v3.0 | 5 votes |
public AutoFocusManager(Context context, Camera camera) { this.camera = camera; String currentFocusMode = camera.getParameters().getFocusMode(); // if (!setCameraContinuousPictureFocus(camera) && !setCameraContinuousFocus(camera)) { useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode); start(); // } else { // useAutoFocus = false; // } }