Java Code Examples for android.hardware.Camera#Size
The following examples show how to use
android.hardware.Camera#Size .
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: Camera1ApiManager.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 7 votes |
/** * @return max size that device can record. */ private Camera.Size getMaxEncoderSizeSupported() { if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) { return camera.new Size(3840, 2160); } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) { return camera.new Size(1920, 1080); } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) { return camera.new Size(1280, 720); } else { return camera.new Size(640, 480); } }
Example 2
Source File: CameraManager.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@SuppressLint("InlinedApi") private static void setDesiredCameraParameters(final Camera camera, final Camera.Size cameraResolution) { final Camera.Parameters parameters = camera.getParameters(); if (parameters == null) { return; } final List<String> supportedFocusModes = parameters.getSupportedFocusModes(); final String focusMode = findValue(supportedFocusModes, Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, Camera.Parameters.FOCUS_MODE_AUTO, Camera.Parameters.FOCUS_MODE_MACRO); if (focusMode != null) { parameters.setFocusMode(focusMode); } parameters.setPreviewSize(cameraResolution.width, cameraResolution.height); camera.setParameters(parameters); }
Example 3
Source File: CameraUtils.java From Telephoto with Apache License 2.0 | 6 votes |
/** Goes through the size list and selects the one which is the closest specified size */ public static int closest(List<Camera.Size> sizes , int width , int height ) { int best = -1; int bestScore = Integer.MAX_VALUE; for( int i = 0; i < sizes.size(); i++ ) { Camera.Size s = sizes.get(i); int dx = s.width-width; int dy = s.height-height; int score = dx*dx + dy*dy; if( score < bestScore ) { best = i; bestScore = score; } } return best; }
Example 4
Source File: CameraPreviewView.java From VideoAndroid with Apache License 2.0 | 6 votes |
private void initCamera() { getHolder().addCallback(this); mCamera.stopPreview(); Camera.Parameters parameters = mCamera.getParameters(); Camera.Size previewSize = CameraHelper.getFullScreenPreviewSize(getContext(), mCamera); // Log.d(TAG, "previewSize " + previewSize.width + "/" + previewSize.height); parameters.setPreviewSize(previewSize.width, previewSize.height); mCamera.setParameters(parameters); // 预览尺寸改变,请求重新布局、计算宽高 requestLayout(); // Set the holder (which might have changed) again try { mCamera.setPreviewDisplay(getHolder()); mCamera.startPreview(); } catch (Exception e) { Log.e(TAG, "Could not set preview display in surfaceChanged"); } //对焦一次 handleFocusMetering(CameraPreviewView.this.getWidth() / 2f, CameraPreviewView.this.getHeight() / 2f); }
Example 5
Source File: CameraConfigurationManager.java From Gizwits-SmartSocket_Android with MIT License | 5 votes |
public void setDesiredCameraParameters(Camera camera, boolean safeMode) { Camera.Parameters parameters = camera.getParameters(); if (parameters == null) { Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); return; } Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); if (safeMode) { Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); } parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); camera.setParameters(parameters); Camera.Parameters afterParameters = camera.getParameters(); Camera.Size afterSize = afterParameters.getPreviewSize(); if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) { Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height); cameraResolution.x = afterSize.width; cameraResolution.y = afterSize.height; } /** 设置相机预览为竖屏 */ camera.setDisplayOrientation(90); }
Example 6
Source File: CameraPreview.java From smartcoins-wallet with MIT License | 5 votes |
private void adjustViewSize(Camera.Size cameraSize) { Point previewSize = convertSizeToLandscapeOrientation(new Point(getWidth(), getHeight())); float cameraRatio = ((float) cameraSize.width) / cameraSize.height; float screenRatio = ((float) previewSize.x) / previewSize.y; if (screenRatio > cameraRatio) { setViewSize((int) (previewSize.y * cameraRatio), previewSize.y); } else { setViewSize(previewSize.x, (int) (previewSize.x / cameraRatio)); } }
Example 7
Source File: TakePhotoActivity.java From clip-image with Apache License 2.0 | 5 votes |
/** * @param sizes * @param defaultSize * @param pictureSize 图片的大小 * @param minRatio preview短边比长边所接受的最小比例 * @return */ private Camera.Size findBestPreviewSize(List<Camera.Size> sizes, Camera.Size defaultSize, Camera.Size pictureSize, float minRatio) { final int pictureWidth = pictureSize.width; final int pictureHeight = pictureSize.height; boolean isBestSize = (pictureHeight / (float)pictureWidth) > minRatio; sortSizes(sizes); Iterator<Camera.Size> it = sizes.iterator(); while (it.hasNext()) { Camera.Size size = it.next(); if ((float) size.height / size.width <= minRatio) { it.remove(); continue; } // 找到同样的比例,直接返回 if (isBestSize && size.width * pictureHeight == size.height * pictureWidth) { return size; } } // 未找到同样的比例的,返回尺寸最大的 if (!sizes.isEmpty()) { return sizes.get(0); } // 没得选,默认吧 return defaultSize; }
Example 8
Source File: FaceDetectGrayActivity.java From FaceDetectCamera with Apache License 2.0 | 5 votes |
private void setOptimalPreviewSize(Camera.Parameters cameraParameters, int width, int height) { List<Camera.Size> previewSizes = cameraParameters.getSupportedPreviewSizes(); float targetRatio = (float) width / height; Camera.Size previewSize = Util.getOptimalPreviewSize(this, previewSizes, targetRatio); previewWidth = previewSize.width; previewHeight = previewSize.height; Log.e(TAG, "previewWidth" + previewWidth); Log.e(TAG, "previewHeight" + previewHeight); /** * Calculate size to scale full frame bitmap to smaller bitmap * Detect face in scaled bitmap have high performance than full bitmap. * The smaller image size -> detect faster, but distance to detect face shorter, * so calculate the size follow your purpose */ if (previewWidth / 4 > 360) { prevSettingWidth = 360; prevSettingHeight = 270; } else if (previewWidth / 4 > 320) { prevSettingWidth = 320; prevSettingHeight = 240; } else if (previewWidth / 4 > 240) { prevSettingWidth = 240; prevSettingHeight = 160; } else { prevSettingWidth = 160; prevSettingHeight = 120; } cameraParameters.setPreviewSize(previewSize.width, previewSize.height); mFaceView.setPreviewWidth(previewWidth); mFaceView.setPreviewHeight(previewHeight); }
Example 9
Source File: Util.java From FFmpegRecorder with GNU General Public License v3.0 | 5 votes |
public static List<Camera.Size> getResolutionList(Camera camera) { Parameters parameters = camera.getParameters(); List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes(); return previewSizes; }
Example 10
Source File: CameraSource.java From fast_qr_reader_view with MIT License | 5 votes |
SizePair( Camera.Size previewSize, @Nullable Camera.Size pictureSize) { preview = new Size(previewSize.width, previewSize.height); if (pictureSize != null) { picture = new Size(pictureSize.width, pictureSize.height); } }
Example 11
Source File: RtspActivity.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
private boolean prepareEncoders() { Camera.Size resolution = rtspCamera1.getResolutionsBack().get(spResolution.getSelectedItemPosition()); int width = resolution.width; int height = resolution.height; return rtspCamera1.prepareVideo(width, height, Integer.parseInt(etFps.getText().toString()), Integer.parseInt(etVideoBitrate.getText().toString()) * 1024, cbHardwareRotation.isChecked(), CameraHelper.getCameraOrientation(this)) && rtspCamera1.prepareAudio(Integer.parseInt(etAudioBitrate.getText().toString()) * 1024, Integer.parseInt(etSampleRate.getText().toString()), rgChannel.getCheckedRadioButtonId() == R.id.rb_stereo, cbEchoCanceler.isChecked(), cbNoiseSuppressor.isChecked()); }
Example 12
Source File: CameraViewProxy.java From Ti-Android-CameraView with MIT License | 5 votes |
private List<Camera.Size> checkSupportedPictureSizeAtPreviewSize(List<Camera.Size> pictureSizes, Camera.Parameters parameters) { List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes(); Camera.Size pictureSize; Camera.Size previewSize; double pictureRatio = 0; double previewRatio = 0; final double aspectTolerance = 0.05; boolean isUsablePicture = false; for (int indexOfPicture = pictureSizes.size() - 1; indexOfPicture >= 0; --indexOfPicture) { pictureSize = pictureSizes.get(indexOfPicture); pictureRatio = (double) pictureSize.width / (double) pictureSize.height; isUsablePicture = false; for (int indexOfPreview = previewSizes.size() - 1; indexOfPreview >= 0; --indexOfPreview) { previewSize = previewSizes.get(indexOfPreview); previewRatio = (double) previewSize.width / (double) previewSize.height; if (Math.abs(pictureRatio - previewRatio) < aspectTolerance) { isUsablePicture = true; break; } } if (isUsablePicture == false) { pictureSizes.remove(indexOfPicture); //Logger.d(TAG, "remove picture size : " + pictureSize.width + ", " + pictureSize.height); } } return pictureSizes; }
Example 13
Source File: JavaCameraView.java From SimpleDocumentScanner-Android with MIT License | 4 votes |
@Override public int getHeight(Object obj) { Camera.Size size = (Camera.Size) obj; return size.height; }
Example 14
Source File: JavaCameraView.java From Camdroid with Apache License 2.0 | 4 votes |
@Override public int getHeight(Object obj) { Camera.Size size = (Camera.Size) obj; return size.height; }
Example 15
Source File: CameraConfigurationManager.java From barcodescanner-lib-aar with MIT License | 4 votes |
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) { Camera theCamera = camera.getCamera(); int rotation = context.getApplicationContext().getResources().getConfiguration().orientation; WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int deviceSpecificRotation = display.getRotation(); if (rotation == Configuration.ORIENTATION_PORTRAIT) { if (deviceSpecificRotation == Surface.ROTATION_0 || deviceSpecificRotation == Surface.ROTATION_90) { theCamera.setDisplayOrientation(90); } else { theCamera.setDisplayOrientation(270); } } else { // landscape if (deviceSpecificRotation == Surface.ROTATION_180 || deviceSpecificRotation == Surface.ROTATION_270) { theCamera.setDisplayOrientation(180); } } Camera.Parameters parameters = theCamera.getParameters(); if (parameters == null) { Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); return; } Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); if (safeMode) { Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); initializeTorch(parameters, prefs, safeMode); CameraConfigurationUtils.setFocus( parameters, prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true), prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true), safeMode); if (!safeMode) { if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) { CameraConfigurationUtils.setInvertColor(parameters); } if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) { CameraConfigurationUtils.setBarcodeSceneMode(parameters); } if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) { CameraConfigurationUtils.setVideoStabilization(parameters); CameraConfigurationUtils.setFocusArea(parameters); CameraConfigurationUtils.setMetering(parameters); } } parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y); theCamera.setParameters(parameters); theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera); Camera.Parameters afterParameters = theCamera.getParameters(); Camera.Size afterSize = afterParameters.getPreviewSize(); if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) { Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height); bestPreviewSize.x = afterSize.width; bestPreviewSize.y = afterSize.height; } }
Example 16
Source File: StreamingBaseActivity.java From PLDroidMediaStreaming with Apache License 2.0 | 4 votes |
@Override public Camera.Size onPreviewSizeSelected(List<Camera.Size> list) { return null; }
Example 17
Source File: VideoOverlay.java From backgroundvideo with GNU General Public License v3.0 | 4 votes |
public void Start(String filePath) throws Exception { if (this.mRecordingState == RecordingState.STARTED) { Log.w(TAG, "Already Recording"); return; } if (!TextUtils.isEmpty(filePath)) { this.mFilePath = filePath; } attachView(); if (this.mRecordingState == RecordingState.INITIALIZING) { this.mStartWhenInitialized = true; return; } if (TextUtils.isEmpty(mFilePath)) { throw new IllegalArgumentException("Filename for recording must be set"); } initializeCamera(); if (mCamera == null) { this.detachView(); throw new NullPointerException("Cannot start recording, we don't have a camera!"); } // Set camera parameters Camera.Parameters cameraParameters = mCamera.getParameters(); mCamera.stopPreview(); //Apparently helps with freezing issue on some Samsung devices. mCamera.unlock(); try { mRecorder = new MediaRecorder(); mRecorder.setCamera(mCamera); CamcorderProfile profile; if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_LOW)) { profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW); } else { profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH); } Camera.Size lowestRes = CameraHelper.getLowestResolution(cameraParameters); profile.videoFrameWidth = lowestRes.width; profile.videoFrameHeight = lowestRes.height; mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); if (mRecordAudio) { // With audio mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setVideoFrameRate(profile.videoFrameRate); mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); mRecorder.setVideoEncodingBitRate(profile.videoBitRate); mRecorder.setAudioEncodingBitRate(profile.audioBitRate); mRecorder.setAudioChannels(profile.audioChannels); mRecorder.setAudioSamplingRate(profile.audioSampleRate); mRecorder.setVideoEncoder(profile.videoCodec); mRecorder.setAudioEncoder(profile.audioCodec); } else { // Without audio mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setVideoFrameRate(profile.videoFrameRate); mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); mRecorder.setVideoEncodingBitRate(profile.videoBitRate); mRecorder.setVideoEncoder(profile.videoCodec); } mRecorder.setOutputFile(filePath); mRecorder.setOrientationHint(mOrientation); mRecorder.prepare(); Log.d(TAG, "Starting recording"); mRecorder.start(); } catch (Exception e) { this.releaseCamera(); Log.e(TAG, "Could not start recording! MediaRecorder Error", e); throw e; } }
Example 18
Source File: CameraConfigurationManager.java From moVirt with Apache License 2.0 | 4 votes |
void setDesiredCameraParameters(Camera camera, boolean safeMode) { Camera.Parameters parameters = camera.getParameters(); if (parameters == null) { Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); return; } Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); if (safeMode) { Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); initializeTorch(parameters, prefs, safeMode); CameraConfigurationUtils.setFocus( parameters, prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true), prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true), safeMode); if (!safeMode) { if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) { CameraConfigurationUtils.setInvertColor(parameters); } if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) { CameraConfigurationUtils.setBarcodeSceneMode(parameters); } if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) { CameraConfigurationUtils.setVideoStabilization(parameters); CameraConfigurationUtils.setFocusArea(parameters); CameraConfigurationUtils.setMetering(parameters); } } parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); Log.i(TAG, "Final camera parameters: " + parameters.flatten()); camera.setParameters(parameters); Camera.Parameters afterParameters = camera.getParameters(); Camera.Size afterSize = afterParameters.getPreviewSize(); if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) { Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height); cameraResolution.x = afterSize.width; cameraResolution.y = afterSize.height; } }
Example 19
Source File: JavaCameraView.java From opencv-documentscanner-android with Apache License 2.0 | 4 votes |
@Override public int getWidth(Object obj) { Camera.Size size = (Camera.Size) obj; return size.width; }
Example 20
Source File: CameraInterface.java From imsdk-android with MIT License | 4 votes |
/** * doStartPreview */ public void doStartPreview(SurfaceHolder holder, float screenProp) { if (isPreviewing) { LogUtil.i("doStartPreview isPreviewing"); } if (this.screenProp < 0) { this.screenProp = screenProp; } if (holder == null) { return; } this.mHolder = holder; if (mCamera != null) { try { mParams = mCamera.getParameters(); Camera.Size previewSize = CameraParamUtil.getInstance().getPreviewSize(mParams .getSupportedPreviewSizes(), 1000, screenProp); Camera.Size pictureSize = CameraParamUtil.getInstance().getPictureSize(mParams .getSupportedPictureSizes(), 1200, screenProp); mParams.setPreviewSize(previewSize.width, previewSize.height); preview_width = previewSize.width; preview_height = previewSize.height; mParams.setPictureSize(pictureSize.width, pictureSize.height); if (CameraParamUtil.getInstance().isSupportedFocusMode( mParams.getSupportedFocusModes(), Camera.Parameters.FOCUS_MODE_AUTO)) { mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } if (CameraParamUtil.getInstance().isSupportedPictureFormats(mParams.getSupportedPictureFormats(), ImageFormat.JPEG)) { mParams.setPictureFormat(ImageFormat.JPEG); mParams.setJpegQuality(100); } mCamera.setParameters(mParams); mParams = mCamera.getParameters(); mCamera.setPreviewDisplay(holder); //SurfaceView mCamera.setDisplayOrientation(cameraAngle);//浏览角度 mCamera.setPreviewCallback(this); //每一帧回调 mCamera.startPreview();//启动浏览 isPreviewing = true; Log.i(TAG, "=== Start Preview ==="); } catch (IOException e) { e.printStackTrace(); } } }