本文整理汇总了Java中android.hardware.Camera.Parameters.setPreviewSize方法的典型用法代码示例。如果您正苦于以下问题:Java Parameters.setPreviewSize方法的具体用法?Java Parameters.setPreviewSize怎么用?Java Parameters.setPreviewSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.Camera.Parameters
的用法示例。
在下文中一共展示了Parameters.setPreviewSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configPreviewSize2
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public BarcodeCameraConfig configPreviewSize2(int viewWidth, int viewHeight) {
Parameters params = camera.getParameters();
List<Size> sizes = params.getSupportedPreviewSizes();
if (sizes == null || sizes.size() <= 0) {
return this;
}
Size bestSize = null;
int diff = Integer.MAX_VALUE;
for (Size tmpSize : sizes) {
int newDiff = Math.abs(tmpSize.width - viewWidth) + Math.abs(tmpSize.height - viewHeight);
if (newDiff == 0) {
bestSize = tmpSize;
break;
} else if (newDiff < diff) {
bestSize = tmpSize;
diff = newDiff;
}
}
params.setPreviewSize(bestSize.width, bestSize.height);
camera.setParameters(params);
return this;
}
示例2: prepare
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public boolean prepare() {
try {
f = new SurfaceTexture(0);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// f.setDefaultBufferSize(10000, 10000);
// }
// SurfaceHolder h = new SurfaceView(JCL_ApplicationContext.getContext()).getHolder();
//mCamera.setPreviewDisplay(h);
mCamera.setPreviewTexture(f);
} catch (IOException e1) {
Log.e("JCLCAMERA", e1.getMessage());
return false;
}
Parameters params = mCamera.getParameters();
params.setPreviewSize(width, height);
params.setPictureSize(width, height);
params.setJpegQuality(50);
params.setFlashMode(Parameters.FLASH_MODE_OFF);
params.setPictureFormat(ImageFormat.JPEG);
mCamera.setParameters(params);
return true;
}
示例3: updateCamera
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
protected synchronized void updateCamera() throws RuntimeException {
if (mPreviewStarted) {
mPreviewStarted = false;
mCamera.stopPreview();
}
Parameters parameters = mCamera.getParameters();
mQuality = VideoQuality.determineClosestSupportedResolution(parameters, mQuality);
int[] max = VideoQuality.determineMaximumSupportedFramerate(parameters);
parameters.setPreviewFormat(mCameraImageFormat);
parameters.setPreviewSize(mQuality.resX, mQuality.resY);
parameters.setPreviewFpsRange(max[0], max[1]);
try {
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(mOrientation);
mCamera.startPreview();
mPreviewStarted = true;
} catch (RuntimeException e) {
destroyCamera();
throw e;
}
}
示例4: setupCameraAndStartPreview
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public void setupCameraAndStartPreview(SurfaceHolder sf, Size sz, int displayRotation) {
stopCameraPreview();
cameraRotationDegree = CameraHelper.setCameraDisplayOrientation(defaultCameraID, camera, displayRotation);
chooseCamcorderProfile(sz);
// tweak profile
profile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;
profile.audioSampleRate = 16000;
profile.audioChannels = 1;
profile.audioBitRate = 96000;
Parameters param = camera.getParameters();
param.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
param.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
if (Build.VERSION.SDK_INT >= 14)
param.setRecordingHint(true);
camera.setParameters(param);
if (setDisplay(sf)) {
startCameraPreview();
}
}
示例5: startPreview
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
private void startPreview(SurfaceHolder holder) {
try {
Parameters params = camera.getParameters();
if (params.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_AUTO)) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
List<Size> previewSizes = camera.getParameters().getSupportedPreviewSizes();
List<Size> pictureSizes = camera.getParameters().getSupportedPictureSizes();
params.setPreviewSize(previewSizes.get(previewSizes.size()-2).width,previewSizes.get(previewSizes.size()-2).height);
params.setPictureSize(pictureSizes.get(pictureSizes.size()-2).width,pictureSizes.get(pictureSizes.size()-2).height);
camera.setParameters(params);
camera.setPreviewDisplay(holder);
camera.startPreview();
previewConsumer.start(camera);
} catch(IOException e) {
Log.e(TAG, "Error starting camera preview", e);
}
}
示例6: setDefaultParameters
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
private static void setDefaultParameters(){
Parameters parameters = mCamera.getParameters();
if (parameters.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
Size previewSize = getLargePreviewSize();
parameters.setPreviewSize(1280, 720);
Size pictureSize = getLargePictureSize();
parameters.setPictureSize(pictureSize.width, pictureSize.height);
mCamera.setParameters(parameters);
}
示例7: setupCameraParameters
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public void setupCameraParameters() {
Size optimalSize = getOptimalPreviewSize();
Parameters parameters = this.mCamera.getParameters();
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
this.mCamera.setParameters(parameters);
adjustViewSize(optimalSize);
}
示例8: updateCamera
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
protected synchronized void updateCamera() throws RuntimeException {
// The camera is already correctly configured
if (mUpdated) return;
if (mPreviewStarted) {
mPreviewStarted = false;
mCamera.stopPreview();
}
Parameters parameters = mCamera.getParameters();
mQuality = VideoQuality.determineClosestSupportedResolution(parameters, mQuality);
int[] max = VideoQuality.determineMaximumSupportedFramerate(parameters);
double ratio = (double)mQuality.resX/(double)mQuality.resY;
mSurfaceView.requestAspectRatio(ratio);
parameters.setPreviewFormat(mCameraImageFormat);
parameters.setPreviewSize(mQuality.resX, mQuality.resY);
parameters.setPreviewFpsRange(max[0], max[1]);
try {
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(mOrientation);
mCamera.startPreview();
mPreviewStarted = true;
mUpdated = true;
} catch (RuntimeException e) {
destroyCamera();
throw e;
}
}
示例9: configureForPreview
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public void configureForPreview(int viewWidth, int viewHeight) {
final Parameters params = mNativeCamera.getNativeCameraParameters();
final CameraSize previewSize = getOptimalSize(params.getSupportedPreviewSizes(), viewWidth, viewHeight);
params.setPreviewSize(previewSize.getWidth(), previewSize.getHeight());
params.setPreviewFormat(ImageFormat.NV21);
mNativeCamera.updateNativeCameraParameters(params);
mNativeCamera.setDisplayOrientation(getRotationCorrection());
CLog.d(CLog.CAMERA, "Preview size: " + previewSize.getWidth() + "x" + previewSize.getHeight());
}
示例10: run
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
@Override
public void run() {
if (mCamera == null) {
return;
}
mCamera.stopPreview();
Parameters params = mCamera.getParameters();
zoomRatios = params.getZoomRatios();
zoomIndex = minZoomIndex = 0;
maxZoomIndex = params.getMaxZoom();
List<Camera.Size> sizes = params.getSupportedPreviewSizes();
List<Camera.Size> vSize = params.getSupportedVideoSizes();
Camera.Size size = CameraHelper.getOptimalPreviewSize(sizes, vSize);
if(size != null)
{
params.setPreviewSize(size.width, size.height);
mCamera.setParameters(params);
resolutionSize = size;
}else {
resolutionSize = null;
}
try {
mCamera.setPreviewDisplay(mHolder);
cameraDisplayOrientation = CameraHelper.getCameraDisplayOrientation(
(Activity)mContext, currentCamera);
mCamera.setDisplayOrientation(cameraDisplayOrientation);
mCamera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: setDefaultParameters
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
private static void setDefaultParameters(){
Parameters parameters = camera.getParameters();
if (parameters.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
Size previewSize = CameraUtils.getLargePreviewSize(camera);
parameters.setPreviewSize(previewSize.width, previewSize.height);
Size pictureSize = CameraUtils.getLargePictureSize(camera);
parameters.setPictureSize(pictureSize.width, pictureSize.height);
parameters.setRotation(90);
camera.setParameters(parameters);
}
示例12: setupCameraAndStartPreview
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public void setupCameraAndStartPreview(SurfaceHolder sf, Size sz, int displayRotation) {
stopCameraPreview();
cameraRotationDegree = CameraHelper.setCameraDisplayOrientation(defaultCameraID, camera, displayRotation);
Parameters param = camera.getParameters();
param.setPreviewSize(sz.width, sz.height);
camera.setParameters(param);
if (setDisplay(sf)) {
startCameraPreview();
}
}
示例13: updateCamera
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
protected synchronized void updateCamera() throws RuntimeException {
// The camera is already correctly configured
if (mUpdated) return;
if (mPreviewStarted) {
mPreviewStarted = false;
mCamera.stopPreview();
}
Parameters parameters = mCamera.getParameters();
mQuality = VideoQuality.determineClosestSupportedResolution(parameters, mQuality);
int[] max = VideoQuality.determineMaximumSupportedFramerate(parameters);
double ratio = (double)mQuality.resX/(double)mQuality.resY;
mSurfaceView.requestAspectRatio(ratio);
parameters.setPreviewFormat(mCameraImageFormat);
parameters.setPreviewSize(mQuality.resX, mQuality.resY);
//int cur_fr = mQuality.framerate * 1000;
//if(max[0] < cur_fr && cur_fr < max[1])
// max[0] = max[1] = cur_fr;
parameters.setPreviewFpsRange(max[0], max[1]);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); //focus
try {
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(mOrientation);
mCamera.startPreview();
//mCamera.cancelAutoFocus();
mPreviewStarted = true;
mUpdated = true;
} catch (RuntimeException e) {
destroyCamera();
throw e;
}
}
示例14: setupCaptureParams
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
private void setupCaptureParams(Parameters parameters) {
List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
if (!findBestPreviewSize(supportedSizes, true, true)) {
Log.w(TAG, "No 4:3 ratio preview size supported.");
if (!findBestPreviewSize(supportedSizes, false, true)) {
Log.w(TAG, "Can't find a supported preview size smaller than 960x720.");
findBestPreviewSize(supportedSizes, false, false);
}
}
Log.d(TAG, "camera preview h = "
+ mCameraPreviewHeight + " , w = " + mCameraPreviewWidth);
parameters.setPreviewSize(mCameraPreviewWidth, mCameraPreviewHeight);
List<int[]> frameRates = parameters.getSupportedPreviewFpsRange();
int last = frameRates.size() - 1;
int minFps = (frameRates.get(last))[Parameters.PREVIEW_FPS_MIN_INDEX];
int maxFps = (frameRates.get(last))[Parameters.PREVIEW_FPS_MAX_INDEX];
parameters.setPreviewFpsRange(minFps, maxFps);
Log.d(TAG, "preview fps: " + minFps + ", " + maxFps);
List<String> supportedFocusModes = parameters.getSupportedFocusModes();
if (supportedFocusModes.indexOf(mTargetFocusMode) >= 0) {
parameters.setFocusMode(mTargetFocusMode);
} else {
// Use the default focus mode and log a message
Log.w(TAG, "Cannot set the focus mode to " + mTargetFocusMode +
" becuase the mode is not supported.");
}
parameters.set(CameraUtil.RECORDING_HINT, CameraUtil.FALSE);
mHorizontalViewAngle = parameters.getHorizontalViewAngle();
mVerticalViewAngle = parameters.getVerticalViewAngle();
}
示例15: surfaceChanged
import android.hardware.Camera.Parameters; //导入方法依赖的package包/类
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
try {
Parameters parameters = camera.getParameters();
Display display = ((WindowManager)mcontext.getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
parameters.setPreviewSize(mPreviewSize.width,mPreviewSize.height);
if(display.getRotation() == Surface.ROTATION_0)
{
camera.setDisplayOrientation(90);
} else if(display.getRotation() == Surface.ROTATION_180)
{
camera.setDisplayOrientation(270);
} else if(display.getRotation() == Surface.ROTATION_270)
{
camera.setDisplayOrientation(180);
}
camera.setParameters(parameters);
camera.startPreview();
} catch (Exception e) {
try {
} catch (Exception ee) {
}
}
}