List of usage examples for android.hardware Camera release
public final void release()
From source file:com.ezartech.ezar.flashlight.Flashlight.java
private void updateLight(int newLightState, final CallbackContext callbackContext) { Camera releaseableCamera = null; try {//from w w w . ja v a2s.co m lightState = newLightState; if (localPreviewCamera == null) { localPreviewCamera = Camera.open(cameraId); } Parameters parameters; parameters = localPreviewCamera.getParameters(); parameters.setFlashMode( newLightState == LIGHT_ON ? Parameters.FLASH_MODE_TORCH : Parameters.FLASH_MODE_OFF); localPreviewCamera.setParameters(parameters); if (localPreviewCamera != null) { if (newLightState == LIGHT_ON) { try { localPreviewCamera.startPreview(); if (hiddenSurfaceTexture == null) { hiddenSurfaceTexture = new SurfaceTexture(0); } localPreviewCamera.setPreviewTexture(hiddenSurfaceTexture); } catch (Exception ex) { callbackContext.error("Unable to start light."); } } else { localPreviewCamera.stopPreview(); releaseableCamera = localPreviewCamera; localPreviewCamera = null; } } } finally { if (releaseableCamera != null) { releaseableCamera.release(); } } if (callbackContext != null) { callbackContext.success(); } }
From source file:ca.nehil.rter.streamingapp.StreamingActivity.java
private Camera openCamera() { Log.d("CameraDebug", "openCamera"); Camera cameraDevice = Camera.open(); numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras && cameraDevice == null; i++) { Log.d("CameraDebug", "opening camera #" + String.valueOf(i)); cameraDevice = Camera.open(i);//from w ww . j a v a2 s. com } try { if (cameraDevice == null) { throw new Exception("No camera device found"); } } catch (Exception e) { Log.d("CameraDebug", "Released cam in openCamera, exception occured"); cameraDevice.release(); cameraDevice = null; Log.e("CameraDebug", e.getMessage()); e.printStackTrace(); } return cameraDevice; }
From source file:com.gsma.rcs.ri.sharing.video.OutgoingVideoSharing.java
/** * Check if good camera sizes are available for encoder. Must be used only before open camera. * * @param cameraId the camera ID//from ww w . j a v a 2s . co m * @return false if the camera don't have the good preview size for the encoder */ boolean checkCameraSize(CameraOptions cameraId) { boolean sizeAvailable = false; Camera camera = null; Method method = getCameraOpenMethod(); if (method != null) { try { camera = (Camera) method.invoke(camera, new Object[] { cameraId.getValue() }); } catch (Exception e) { camera = Camera.open(); } } else { camera = Camera.open(); } if (camera == null) { return false; } // Check common sizes Parameters param = camera.getParameters(); List<Camera.Size> sizes = param.getSupportedPreviewSizes(); for (Camera.Size size : sizes) { if ((size.width == H264Config.QVGA_WIDTH && size.height == H264Config.QVGA_HEIGHT) || (size.width == H264Config.CIF_WIDTH && size.height == H264Config.CIF_HEIGHT) || (size.width == H264Config.VGA_WIDTH && size.height == H264Config.VGA_HEIGHT)) { sizeAvailable = true; break; } } // Release camera camera.release(); return sizeAvailable; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
private String[] getSupportedOtherCamera(int cam) { Camera camera = Camera.open(cam); if (camera != null) { try {/*from w w w .j a v a 2s. c o m*/ String[] stringList = new String[7]; android.hardware.Camera.Parameters parameters = camera.getParameters(); String values = "Focus mode: " + parameters.getFocusMode(); stringList[0] = values; values = "Max Num Focus Areas: " + parameters.getMaxNumFocusAreas(); stringList[1] = values; values = "Whitebalance Values: " + parameters.getSupportedWhiteBalance(); stringList[2] = values; values = "Scene mode Values: " + parameters.getSupportedSceneModes(); stringList[3] = values; values = "Effects Values: " + parameters.getSupportedColorEffects(); stringList[4] = values; values = "Stabilization Video: " + parameters.getVideoStabilization(); stringList[4] = values; values = "Quality JPEG: " + parameters.getJpegQuality(); stringList[5] = values; values = "Quality Thumbnail: " + parameters.getJpegThumbnailQuality(); stringList[6] = values; camera.release(); return stringList; } catch (RuntimeException e) { e.printStackTrace(); } } return null; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
private String[] getSupportedPreviewSizesVideo(int cam) { float mp = 0, temp, height, width; Camera camera = Camera.open(cam); if (camera != null) { try {//from w w w . ja va2 s . co m android.hardware.Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> values = parameters.getSupportedVideoSizes(); List<String> valuessupport = new ArrayList<String>(); for (int i = 0; i < values.size(); i++) { String strSize = String.valueOf(i) + " : " + String.valueOf(values.get(i).height) + " x " + String.valueOf(values.get(i).width); valuessupport.add(strSize); if (i == 0) { height = Float.parseFloat(String.valueOf(values.get(i).height)); width = Float.parseFloat(String.valueOf(values.get(i).width)); temp = ((height * width) / 1024000); mp = temp; } else { height = Float.parseFloat(String.valueOf(values.get(i).height)); width = Float.parseFloat(String.valueOf(values.get(i).width)); temp = ((height * width) / 1024000); if (temp > mp) { mp = temp; } if (i == values.size() - 1) { //valuessupport.add(String.valueOf(mp)+" Megapixels"); } } } camera.release(); Log.i("#######################################", String.valueOf(valuessupport)); String[] stringList = valuessupport.toArray(new String[valuessupport.size()]); return stringList; } catch (RuntimeException e) { e.printStackTrace(); } } return null; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
@TargetApi(Build.VERSION_CODES.ECLAIR) private String[] getSupportedPreviewSizes(int cam) { float mp = 0, temp, height, width; Camera camera = Camera.open(cam); if (camera != null) { try {//from w ww . j a v a 2 s . c o m android.hardware.Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> values = parameters.getSupportedPictureSizes(); List<String> valuessupport = new ArrayList<String>(); for (int i = 0; i < values.size(); i++) { String strSize = String.valueOf(i) + " : " + String.valueOf(values.get(i).height) + " x " + String.valueOf(values.get(i).width); valuessupport.add(strSize); if (i == 0) { height = Float.parseFloat(String.valueOf(values.get(i).height)); width = Float.parseFloat(String.valueOf(values.get(i).width)); temp = ((height * width) / 1024000); mp = temp; } else { height = Float.parseFloat(String.valueOf(values.get(i).height)); width = Float.parseFloat(String.valueOf(values.get(i).width)); temp = ((height * width) / 1024000); if (temp > mp) { mp = temp; } if (i == values.size() - 1) { valuessupport.add(String.valueOf(mp) + " Megapixels"); } } } camera.release(); Log.i("#######################################", String.valueOf(valuessupport)); String[] stringList = valuessupport.toArray(new String[valuessupport.size()]); return stringList; } catch (RuntimeException e) { e.printStackTrace(); } } return null; }