当前位置: 首页>>代码示例>>Java>>正文


Java Camera.setParameters方法代码示例

本文整理汇总了Java中android.hardware.Camera.setParameters方法的典型用法代码示例。如果您正苦于以下问题:Java Camera.setParameters方法的具体用法?Java Camera.setParameters怎么用?Java Camera.setParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.Camera的用法示例。


在下文中一共展示了Camera.setParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTorchEnabled

import android.hardware.Camera; //导入方法依赖的package包/类
private static void setTorchEnabled(final Camera camera, final boolean enabled) {
    final Camera.Parameters parameters = camera.getParameters();

    final List<String> supportedFlashModes = parameters.getSupportedFlashModes();
    if (supportedFlashModes != null) {
        final String flashMode;
        if (enabled)
            flashMode = findValue(supportedFlashModes, Camera.Parameters.FLASH_MODE_TORCH,
                    Camera.Parameters.FLASH_MODE_ON);
        else
            flashMode = findValue(supportedFlashModes, Camera.Parameters.FLASH_MODE_OFF);

        if (flashMode != null) {
            camera.cancelAutoFocus(); // autofocus can cause conflict

            parameters.setFlashMode(flashMode);
            camera.setParameters(parameters);
        }
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:CameraManager.java

示例2: setDesiredCameraParameters

import android.hardware.Camera; //导入方法依赖的package包/类
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {
  Camera theCamera = camera.getCamera();
  Camera.Parameters parameters = theCamera.getParameters();

  Log.d(TAG, "Setting preview size: " + cameraResolution);
  parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
  setFlash(parameters);
  setZoom(parameters);
  theCamera.setDisplayOrientation(cwNeededRotation);
  theCamera.setParameters(parameters);

  Camera.Size afterSize = parameters.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;
  }
}
 
开发者ID:10045125,项目名称:QrCode,代码行数:20,代码来源:CameraConfigurationManager.java

示例3: switchCamera

import android.hardware.Camera; //导入方法依赖的package包/类
public void switchCamera(Camera camera, int cameraId) {
  try {
    setCamera(camera, cameraId);

    Log.d("CameraPreview", "before set camera");

    camera.setPreviewDisplay(mHolder);

    Log.d("CameraPreview", "before getParameters");

    Camera.Parameters parameters = camera.getParameters();

    Log.d("CameraPreview", "before setPreviewSize");

    mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
    mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, mSurfaceView.getWidth(), mSurfaceView.getHeight());
    parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
    Log.d(TAG, mPreviewSize.width + " " + mPreviewSize.height);

    camera.setParameters(parameters);
  } catch (IOException exception) {
    Log.e(TAG, exception.getMessage());
  }
}
 
开发者ID:MrShakes,项目名称:cameraPreviewStream,代码行数:25,代码来源:Preview.java

示例4: adjustCameraRotationToDeviceOrientation

import android.hardware.Camera; //导入方法依赖的package包/类
public void adjustCameraRotationToDeviceOrientation(int type, int deviceOrientation) {
    Camera camera = _cameras.get(type);
    if (null == camera) {
        return;
    }

    CameraInfoWrapper cameraInfo = _cameraInfos.get(type);
    int rotation;
    int orientation = cameraInfo.info.orientation;
    if (cameraInfo.info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        rotation = (orientation + deviceOrientation * 90) % 360;
    } else {
        rotation = (orientation - deviceOrientation * 90 + 360) % 360;
    }
    cameraInfo.rotation = rotation;
    Camera.Parameters parameters = camera.getParameters();
    parameters.setRotation(cameraInfo.rotation);

    try {
        camera.setParameters(parameters);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:entria,项目名称:react-native-camera-face-detector,代码行数:25,代码来源:RCTCamera.java

示例5: setTorchMode

import android.hardware.Camera; //导入方法依赖的package包/类
public void setTorchMode(int cameraType, int torchMode) {
    Camera camera = this.acquireCameraInstance(cameraType);
    if (null == camera) {
        return;
    }

    Camera.Parameters parameters = camera.getParameters();
    String value = parameters.getFlashMode();
    switch (torchMode) {
        case RCTCameraModule.RCT_CAMERA_TORCH_MODE_ON:
            value = Camera.Parameters.FLASH_MODE_TORCH;
            break;
        case RCTCameraModule.RCT_CAMERA_TORCH_MODE_OFF:
            value = Camera.Parameters.FLASH_MODE_OFF;
            break;
    }

    List<String> flashModes = parameters.getSupportedFlashModes();
    if (flashModes != null && flashModes.contains(value)) {
        parameters.setFlashMode(value);
        camera.setParameters(parameters);
    }
}
 
开发者ID:jonathan68,项目名称:react-native-camera,代码行数:24,代码来源:RCTCamera.java

示例6: stopPreviewInternal

import android.hardware.Camera; //导入方法依赖的package包/类
private void stopPreviewInternal(boolean internal) {
    try {
        DecoderWrapper decoderWrapper = mDecoderWrapper;
        Camera camera = decoderWrapper.getCamera();
        if (!internal && decoderWrapper.isFlashSupported() && mFlashEnabled) {
            Camera.Parameters parameters = camera.getParameters();
            if (parameters != null && Utils.setFlashMode(parameters, Camera.Parameters.FLASH_MODE_OFF)) {
                camera.setParameters(parameters);
            }
        }
        camera.setPreviewCallback(null);
        camera.stopPreview();
    } catch (Exception ignored) {
    }
    mStoppingPreview = false;
    mPreviewActive = false;
    mSafeAutoFocusing = false;
    mSafeAutoFocusAttemptsCount = 0;
}
 
开发者ID:yuriy-budiyev,项目名称:code-scanner,代码行数:20,代码来源:CodeScanner.java

示例7: setCameraParam

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * 设置相机参数
 *
 * @param mCamera canmea
 */
static void setCameraParam(Camera mCamera) {
    try {
        Camera.Parameters mParameters = mCamera.getParameters();
        String mode = ERecorderActivityImpl.getAutoFocusMode(mParameters);
        if (!StringUtil.isEmpty(mode)) {
            mParameters.setFocusMode(mode);
        }

        if (ERecorderActivityImpl.isSupported(mParameters.getSupportedWhiteBalance(), "auto")) {
            mParameters.setWhiteBalance("auto");
        }

        if ("true".equals(mParameters.get("video-stabilization-supported"))) {
            mParameters.set("video-stabilization", "true");
        }

        if (!DeviceUtils.isDevice("GT-N7100", "GT-I9308", "GT-I9300")) {
            mParameters.set("cam_mode", 1);
            mParameters.set("cam-mode", 1);
        }
        mCamera.setParameters(mParameters);
    } catch (Exception e) {
        e.printStackTrace();
    }

    int orientation = 90;
    mCamera.setDisplayOrientation(orientation);
}
 
开发者ID:f-evil,项目名称:EVideoRecorder,代码行数:34,代码来源:ERecorderActivityImpl.java

示例8: setDesiredCameraParameters

import android.hardware.Camera; //导入方法依赖的package包/类
public void setDesiredCameraParameters(Camera camera) {
		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);
	}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:29,代码来源:CameraConfigurationManager.java

示例9: doSetTorch

import android.hardware.Camera; //导入方法依赖的package包/类
private void doSetTorch(Camera camera, boolean newSetting) {
    Camera.Parameters parameters = camera.getParameters();
    String flashMode;
    /** 是否支持闪光灯 */
    if (newSetting) {
        flashMode = findSettableValue(parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_TORCH, Camera.Parameters.FLASH_MODE_ON);
    } else {
        flashMode = findSettableValue(parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_OFF);
    }
    if (flashMode != null) {
        parameters.setFlashMode(flashMode);
    }
    camera.setParameters(parameters);
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:15,代码来源:CameraConfigurationManager.java

示例10: createCamera

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens the camera and applies the user settings.
 *
 * @throws RuntimeException if the method fails
 */
@SuppressLint("InlinedApi")
private Camera createCamera() {
    int requestedCameraId = getIdForRequestedCamera(mFacing);
    if (requestedCameraId == -1) {
        throw new RuntimeException("Could not find requested camera.");
    }
    Camera camera = Camera.open(requestedCameraId);

    SizePair sizePair = selectSizePair(camera, mRequestedPreviewWidth, mRequestedPreviewHeight);
    if (sizePair == null) {
        throw new RuntimeException("Could not find suitable preview size.");
    }
    Size pictureSize = sizePair.pictureSize();
    mPreviewSize = sizePair.previewSize();

    int[] previewFpsRange = selectPreviewFpsRange(camera, mRequestedFps);
    if (previewFpsRange == null) {
        throw new RuntimeException("Could not find suitable preview frames per second range.");
    }

    Camera.Parameters parameters = camera.getParameters();

    if (pictureSize != null) {
        parameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
    }

    parameters.setPreviewSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
    parameters.setPreviewFpsRange(
            previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
            previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
    parameters.setPreviewFormat(ImageFormat.NV21);

    setRotation(camera, parameters, requestedCameraId);

    if (mFocusMode != null) {
        if (parameters.getSupportedFocusModes().contains(
                mFocusMode)) {
            parameters.setFocusMode(mFocusMode);
        } else {
            Log.i(TAG, "Camera focus mode: " + mFocusMode +
                    " is not supported on this device.");
        }
    }

    // setting mFocusMode to the one set in the params
    mFocusMode = parameters.getFocusMode();

    if (mFlashMode != null) {
        if (parameters.getSupportedFlashModes().contains(
                mFlashMode)) {
            parameters.setFlashMode(mFlashMode);
        } else {
            Log.i(TAG, "Camera flash mode: " + mFlashMode +
                    " is not supported on this device.");
        }
    }

    // setting mFlashMode to the one set in the params
    mFlashMode = parameters.getFlashMode();

    camera.setParameters(parameters);

    // Four frame buffers are needed for working with the camera:
    //
    //   one for the frame that is currently being executed upon in doing detection
    //   one for the next pending frame to process immediately upon completing detection
    //   two for the frames that the camera uses to populate future preview images
    camera.setPreviewCallbackWithBuffer(new CameraPreviewCallback());
    camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize));
    camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize));
    camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize));
    camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize));

    return camera;
}
 
开发者ID:OlayinkaPeter,项目名称:Toodoo,代码行数:81,代码来源:CameraSource.java

示例11: openDriver

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    OpenCamera theCamera = camera;
    if (theCamera == null) {
        theCamera = OpenCameraInterface.open(requestedCameraId);
        if (theCamera == null) {
            throw new IOException("Camera.open() failed to return object from driver");
        }
        camera = theCamera;
    }

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera cameraObject = theCamera.getCamera();
    Camera.Parameters parameters = cameraObject.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = cameraObject.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                cameraObject.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }
    cameraObject.setPreviewDisplay(holder);

}
 
开发者ID:10045125,项目名称:QrCode,代码行数:52,代码来源:CameraManager.java

示例12: disableSceneMode

import android.hardware.Camera; //导入方法依赖的package包/类
@UiThread
private Parameters disableSceneMode(Camera camera, Parameters params) {
	params.setSceneMode(SCENE_MODE_AUTO);
	camera.setParameters(params);
	return camera.getParameters();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:7,代码来源:CameraView.java

示例13: openDriver

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {

		if (requestedCameraId >= 0) {
			theCamera = OpenCameraInterface.open(requestedCameraId);
		} else {
			theCamera = OpenCameraInterface.open();
		}

		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
	}

	Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
																					// these,
																					// temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	} catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			} catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}
 
开发者ID:AnyRTC,项目名称:anyRTC-RTCP-Android,代码行数:57,代码来源:CameraManager.java

示例14: openDriver

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames
 *               into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {

        if (requestedCameraId >= 0) {
            theCamera = OpenCameraInterface.open(requestedCameraId);
        } else {
            theCamera = OpenCameraInterface.open();
        }

        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
    // these,
    // temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }

}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:55,代码来源:CameraManager.java

示例15: openDriver

import android.hardware.Camera; //导入方法依赖的package包/类
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {

		if (requestedCameraId >= 0) {
			theCamera = OpenCameraInterface.open(requestedCameraId);
		} else {
			theCamera = OpenCameraInterface.open();
		}

		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
	}

	Camera.Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
																					// these,
																					// temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	} catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			} catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}
 
开发者ID:TonnyL,项目名称:Espresso,代码行数:57,代码来源:CameraManager.java


注:本文中的android.hardware.Camera.setParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。