本文整理汇总了Java中android.hardware.Camera类的典型用法代码示例。如果您正苦于以下问题:Java Camera类的具体用法?Java Camera怎么用?Java Camera使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Camera类属于android.hardware包,在下文中一共展示了Camera类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: surfaceChanged
import android.hardware.Camera; //导入依赖的package包/类
@Override
public void surfaceChanged(final SurfaceHolder holder, int format, int width, int height) {
if (mycamera != null) {
mycamera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
if (success) {
synchronized (camera) {
new Thread() {
public void run() {
initCamera(holder);
super.run();
}
}.start();
}
}
}
});
}
}
示例2: createCameraSource
import android.hardware.Camera; //导入依赖的package包/类
private void createCameraSource() {
// Create the TextRecognizer
TextRecognizer textRecognizer = new TextRecognizer.Builder(getContext()).build();
SearchResultHandler searchResultHandler = new SearchResultHandler(getContext(), mPreferenceManager, getResources().getStringArray(R.array.pin_colors));
// Set the TextRecognizer's Processor.
OcrDetectorProcessor ocrDetectorProcessor = new OcrDetectorProcessor(
mOcrGraphicOverlay,
mMaskView,
mPreferenceManager,
searchResultHandler,
mScanPresenter);
textRecognizer.setProcessor(ocrDetectorProcessor);
mScanPresenter.setProcessor(ocrDetectorProcessor);
// Check if the TextRecognizer is operational.
if (!textRecognizer.isOperational()) {
Log.w(TAG, "Detector dependencies are not yet available.");
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(getContext(), R.string.low_storage_error, Toast.LENGTH_LONG).show();
Log.w(TAG, getString(R.string.low_storage_error));
}
}
// Create the mCameraSource using the TextRecognizer.
mCameraSource = new CameraSource.Builder(getContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setRequestedFps(15.0f)
// .setFlashMode(Camera.Parameters.FLASH_MODE_TORCH)
.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)
.build();
}
示例3: focusOnTouch
import android.hardware.Camera; //导入依赖的package包/类
private void focusOnTouch(int x, int y, Camera camera) {
Rect rect = new Rect(x - 100, y - 100, x + 100, y + 100);
int left = rect.left * 2000 / getWidth() - 1000;
int top = rect.top * 2000 / getHeight() - 1000;
int right = rect.right * 2000 / getWidth() - 1000;
int bottom = rect.bottom * 2000 / getHeight() - 1000;
// 如果超出了(-1000,1000)到(1000, 1000)的范围,则会导致相机崩溃
left = left < -1000 ? -1000 : left;
top = top < -1000 ? -1000 : top;
right = right > 1000 ? 1000 : right;
bottom = bottom > 1000 ? 1000 : bottom;
try {
focusOnRect(new Rect(left, top, right, bottom), camera);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: configureRecorder
import android.hardware.Camera; //导入依赖的package包/类
protected void configureRecorder(int quality, MediaRecorder recorder) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraInfo.cameraId, info);
int displayOrientation = getDisplayOrientation(info, false);
recorder.setOrientationHint(displayOrientation);
int highProfile = getHigh();
boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
if (canGoHigh && (quality == 1 || !canGoLow)) {
recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
} else if (canGoLow) {
recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
} else {
throw new IllegalStateException("cannot find valid CamcorderProfile");
}
isVideo = true;
}
示例5: hasFlash
import android.hardware.Camera; //导入依赖的package包/类
/**
* Check if this device has flash
*/
public static boolean hasFlash(Camera mCamera) {
if (mCamera == null) {
return false;
}
Camera.Parameters parameters = mCamera.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;
}
return true;
}
示例6: onCameraSurfaceCreate
import android.hardware.Camera; //导入依赖的package包/类
@Override
public void onCameraSurfaceCreate(SurfaceTexture surfaceTexture) {
Log.d(TAG, "onCameraSurfaceCreate");
mCamera = Camera.open();
Camera.Parameters parameters = mCamera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
mVideoRecorder.createInputSurfaceWindow(EGL14.eglGetCurrentContext());
try {
parameters.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCameraView.setPreviewSize(PREVIEW_HEIGHT, PREVIEW_WIDTH);
mVideoRecorder.setPreviewSize(PREVIEW_HEIGHT, PREVIEW_WIDTH);
mCamera.setParameters(parameters);
mCamera.setPreviewTexture(surfaceTexture);
mCamera.setDisplayOrientation(Profile.ORIENTATION_90);
mCamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
isSurfaceReady = true;
}
示例7: onCreate
import android.hardware.Camera; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a container that will hold a SurfaceView for camera previews
mPreview = new Preview(this.getActivity());
// Find the total number of cameras available
mNumberOfCameras = Camera.getNumberOfCameras();
// Find the ID of the rear-facing ("default") camera
CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < mNumberOfCameras; i++) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
mCurrentCamera = mDefaultCameraId = i;
}
}
setHasOptionsMenu(mNumberOfCameras > 1);
}
示例8: openCamera
import android.hardware.Camera; //导入依赖的package包/类
private void openCamera()
{
new Thread(new Runnable() {
@Override
public void run() {
mCamera = getCameraInstance();
if (mCamera != null) {
mCamera.setDisplayOrientation(90);
Camera.Parameters cameraParameters = mCamera.getParameters();
cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
mCamera.setParameters(cameraParameters);
}
Message message = handler.obtainMessage(OPEN_CAMERA, 1);
message.sendToTarget();
}
}).start();
}
示例9: 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 void openDriver(SurfaceHolder holder) throws IOException {
if (camera == null) {
camera = Camera.open();
if (camera == null) {
throw new IOException();
}
camera.setPreviewDisplay(holder);
if (!initialized) {
initialized = true;
configManager.initFromCameraParameters(camera);
}
configManager.setDesiredCameraParameters(camera);
//FIXME
FlashlightManager.enableFlashlight();
}
}
示例10: manualFocus
import android.hardware.Camera; //导入依赖的package包/类
/**
* 手动对焦
*
* @param focusAreas 对焦区域
* @return
*/
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean manualFocus(AutoFocusCallback cb, List<Area> focusAreas) {
if (camera != null && focusAreas != null && mParameters != null && DeviceUtils.hasICS()) {
try {
camera.cancelAutoFocus();
// getMaxNumFocusAreas检测设备是否支持
if (mParameters.getMaxNumFocusAreas() > 0) {
// mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);//
// Macro(close-up) focus mode
mParameters.setFocusAreas(focusAreas);
}
if (mParameters.getMaxNumMeteringAreas() > 0)
mParameters.setMeteringAreas(focusAreas);
mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
camera.setParameters(mParameters);
camera.autoFocus(cb);
return true;
} catch (Exception e) {
if (mOnErrorListener != null) {
mOnErrorListener.onVideoError(MEDIA_ERROR_CAMERA_AUTO_FOCUS, 0);
}
if (e != null)
Log.e("Yixia", "autoFocus", e);
}
}
return false;
}
示例11: setFlashInternal
import android.hardware.Camera; //导入依赖的package包/类
/**
* @return {@code true} if {@link #mCameraParameters} was modified.
*/
private boolean setFlashInternal(int flash) {
if (isCameraOpened()) {
List<String> modes = mCameraParameters.getSupportedFlashModes();
String mode = FLASH_MODES.get(flash);
if (modes != null && modes.contains(mode)) {
mCameraParameters.setFlashMode(mode);
mFlash = flash;
return true;
}
String currentMode = FLASH_MODES.get(mFlash);
if (modes == null || !modes.contains(currentMode)) {
mCameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
mFlash = Constants.FLASH_OFF;
return true;
}
return false;
} else {
mFlash = flash;
return false;
}
}
示例12: startCamera
import android.hardware.Camera; //导入依赖的package包/类
public Camera startCamera(){
try {
if(Camera.getNumberOfCameras()>1){
camera = Camera.open(1);
Facing = getFacing(1);
id++;
}else{
camera = Camera.open(0);
Facing = getFacing(0);
id++;
}
}catch (RuntimeException e){
Toast.makeText(context, "打开相机失败,请解除占用!", Toast.LENGTH_LONG).show();
}
return camera;
}
示例13: startAutoFocus
import android.hardware.Camera; //导入依赖的package包/类
public boolean startAutoFocus(Camera.AutoFocusCallback autoFocusCallback) {
if ((mIsSupportAutoFocus || mIsSupportAutoFocusContinuousPicture) && mCamera != null) {
try {
String focusMode = getCameraParameters().getFocusMode();
if (!TextUtils.isEmpty(focusMode) && focusMode.
equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { // 如果是连续自动对焦, 来一次对焦处理
mCamera.autoFocus(autoFocusCallback);
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return false;
}
示例14: onResume
import android.hardware.Camera; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
if (mCamera == null) {
try {
mCamera = Camera.open();
mCamera.setPreviewDisplay(mCameraPreview.getHolder());
if (mIsCapturing) {
mCamera.setDisplayOrientation(90);
mCamera.startPreview();
}
} catch (Exception e) {
Toast.makeText(CameraActivity.this, "Unable to open camera. Please go to settings for camera permission", Toast.LENGTH_SHORT )
.show();
}
}
}
示例15: autoFocus
import android.hardware.Camera; //导入依赖的package包/类
/**
* This method is only valid when preview is active
* (between {@link Camera#startPreview()} and before {@link Camera#stopPreview()}).
*/
private void autoFocus() {
if (mCamera == null) {
return;
}
Camera.Parameters cameraParam = mCamera.getParameters();
List<String> focusModes = cameraParam.getSupportedFocusModes();
if (focusModes == null) {
return;
}
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
// Autofocus mode is supported
// get Camera parameters
// set the focus mode
cameraParam.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
// set Camera parameters
mCamera.setParameters(cameraParam);
mCamera.autoFocus(mFocusCallback);
}
}