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


Java CameraAccessException类代码示例

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


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

示例1: setManualFocusAt

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
void setManualFocusAt(int x, int y) {
    int mDisplayOrientation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
    float points[] = new float[2];
    points[0] = (float) x / mTextureView.getWidth();
    points[1] = (float) y / mTextureView.getHeight();
    Matrix rotationMatrix = new Matrix();
    rotationMatrix.setRotate(mDisplayOrientation, 0.5f, 0.5f);
    rotationMatrix.mapPoints(points);
    if (mPreviewRequestBuilder != null) {
        mIsManualFocusing = true;
        updateManualFocus(points[0], points[1]);
        if (mPreviewSession != null) {
            try {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CaptureRequest.CONTROL_AF_TRIGGER_START);
                mPreviewSession.capture(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
                mPreviewSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
                    null, mBackgroundHandler);
            } catch (CameraAccessException | IllegalStateException e) {
                Log.e(TAG, "Failed to set manual focus.", e);
            }
        }
        resumeAutoFocusAfterManualFocus();
    }
}
 
开发者ID:lytcom,项目名称:CameraKitView,代码行数:28,代码来源:Camera2Fragment.java

示例2: setFlash

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
void setFlash(int flash) {
    if (mFlash == flash) {
        return;
    }
    int saved = mFlash;
    mFlash = flash;
    if (mPreviewRequestBuilder != null) {
        updateFlash();
        if (mCaptureSession != null) {
            try {
                mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
                        mCaptureCallback, null);
            } catch (CameraAccessException e) {
                mFlash = saved; // Revert
            }
        }
    }
}
 
开发者ID:wajahatkarim3,项目名称:LongImageCamera,代码行数:20,代码来源:Camera2.java

示例3: unlockFocus

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:21,代码来源:Camera2BasicFragment.java

示例4: onOpened

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
public void onOpened(CameraDevice camera) {
  checkIsOnCameraThread();

  Logging.d(TAG, "Camera opened.");
  cameraDevice = camera;

  final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
  surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
  surface = new Surface(surfaceTexture);
  List<Surface> surfaces = new ArrayList<Surface>();
  surfaces.add(surface);
  if (mediaRecorderSurface != null) {
    Logging.d(TAG, "Add MediaRecorder surface to capture session.");
    surfaces.add(mediaRecorderSurface);
  }
  try {
    camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
  } catch (CameraAccessException e) {
    reportError("Failed to create capture session. " + e);
    return;
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:24,代码来源:Camera2Session.java

示例5: unlockFocus

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
            mBackgroundHandler);

        updateAutoFocus();
        updateFlash(mPreviewRequestBuilder);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
            mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:lytcom,项目名称:CameraKitView,代码行数:25,代码来源:Camera2Fragment.java

示例6: setupCameraIfNeeded

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private boolean setupCameraIfNeeded() {
    if (cameraId != null) {
        return true;
    }
    try {
        cameraId = cameraManager.getCameraIdList()[0];  // Usually back camera is at 0 position
    } catch (CameraAccessException e) {
        Log.v(TAG, "failed to set up camera");
        return false;
    }
    torchEnabled = false;
    Handler handler = new Handler();
    torchCallback = new CameraManager.TorchCallback() {
        @Override
        public void onTorchModeChanged(@NonNull String cameraId, boolean enabled) {
            super.onTorchModeChanged(cameraId, enabled);
            torchEnabled = enabled;
        }
    };
    cameraManager.registerTorchCallback(torchCallback, handler);
    Log.v(TAG, "registered torch callback");
    return true;
}
 
开发者ID:Shingyx,项目名称:Bixlight,代码行数:24,代码来源:BixlightService.java

示例7: setAutoFocus

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
void setAutoFocus(boolean autoFocus) {
    if (mAutoFocus == autoFocus) {
        return;
    }
    mAutoFocus = autoFocus;
    if (mPreviewRequestBuilder != null) {
        updateAutoFocus();
        if (mCaptureSession != null) {
            try {
                mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
                        mCaptureCallback, null);
            } catch (CameraAccessException e) {
                mAutoFocus = !mAutoFocus; // Revert
            }
        }
    }
}
 
开发者ID:vshkl,项目名称:PXLSRT,代码行数:19,代码来源:Camera2.java

示例8: startCaptureSession

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * <p>Starts a capture session for camera preview.</p>
 * <p>This rewrites {@link #mPreviewRequestBuilder}.</p>
 * <p>The result will be continuously processed in {@link #mSessionCallback}.</p>
 */
void startCaptureSession() {
    if (!isCameraOpened() || !mPreview.isReady() || mImageReader == null) {
        return;
    }
    Size previewSize = chooseOptimalSize();
    mPreview.setBufferSize(previewSize.getWidth(), previewSize.getHeight());
    Surface surface = mPreview.getSurface();
    try {
        mPreviewRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);
        mCamera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
                mSessionCallback, null);
    } catch (CameraAccessException e) {
        throw new RuntimeException("Failed to start camera session");
    }
}
 
开发者ID:vshkl,项目名称:PXLSRT,代码行数:22,代码来源:Camera2.java

示例9: openCamera

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
     * 相机开启
     * @param width     TextureView的宽度
     * @param height    TextureView的高度
     */
    private void openCamera(int width, int height) {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
//            requestCameraPermission();
            return;
        }
        setUpCameraOutputs(width, height);
        configureTransform(width, height);
        try {
            cameraManager.openCamera(cameraID, deviceStateCallback, mainHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:21,代码来源:CalibrationActivity.java

示例10: unlockFocus

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * Unlocks the auto-focus and restart camera preview. This is supposed to be called after
 * capturing a still picture.
 */
void unlockFocus() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        updateAutoFocus();
        updateFlash();
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                null);
        mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to restart camera preview.", e);
    }
}
 
开发者ID:vshkl,项目名称:PXLSRT,代码行数:21,代码来源:Camera2.java

示例11: openCamera

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private void openCamera(String cameraId) {
        try {
//            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
//            characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
            if (ActivityCompat.checkSelfPermission(getContext(), permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            setUpCameraOutputs(cameraId, ttv_camera.getWidth(), ttv_camera.getHeight());
            configureTransform(ttv_camera.getWidth(), ttv_camera.getHeight());
            mCameraManager.openCamera(cameraId, mCameraDeviceStateCallback, mHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:vipycm,项目名称:mao-android,代码行数:22,代码来源:Camera2Fragment.java

示例12: setRepeatingBurst

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * Set a repeating burst request.
 */
public void setRepeatingBurst(final List<CaptureRequest> requests,
        final CameraCaptureSession.CaptureCallback listener, final Handler handler) {
    mCameraHandler.post(() -> {
        try {
            mCameraSession.setRepeatingBurst(requests, listener, handler);
        } catch (CameraAccessException e) {
            String errorMessage = mErrorDisplayer.getErrorString(e);
            mErrorDisplayer.showErrorDialog(errorMessage);
        }
    });
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:15,代码来源:CameraOps.java

示例13: start

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private void start() {
  checkIsOnCameraThread();
  Logging.d(TAG, "start");

  try {
    cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
  } catch (final CameraAccessException e) {
    reportError("getCameraCharacteristics(): " + e.getMessage());
    return;
  }
  cameraOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
  isCameraFrontFacing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
      == CameraMetadata.LENS_FACING_FRONT;

  findCaptureFormat();
  openCamera();
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:18,代码来源:Camera2Session.java

示例14: takePicture

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
 * Begin a still image capture
 */
public void takePicture() {
    if (mCameraDevice == null) {
        Log.w(TAG, "Cannot capture image. Camera not initialized.");
        return;
    }
    // Here, we create a CameraCaptureSession for capturing still images.
    try {
        mCameraDevice.createCaptureSession(
                Collections.singletonList(mImageReader.getSurface()),
                mSessionCallback,
                null);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "access exception while preparing pic", cae);
    }
}
 
开发者ID:googlecodelabs,项目名称:androidthings-imageclassifier,代码行数:19,代码来源:CameraHandler.java

示例15: setFlashlight

import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
public void setFlashlight(boolean enabled) {
    boolean pendingError = false;
    synchronized (this) {
        if (mFlashlightEnabled != enabled) {
            mFlashlightEnabled = enabled;
            try {
                mCameraManager.setTorchMode(mCameraId, enabled);
            } catch (CameraAccessException e) {
                Log.e(TAG, "Couldn't set torch mode", e);
                mFlashlightEnabled = false;
                pendingError = true;
            }
        }
    }
    dispatchModeChanged(mFlashlightEnabled);
    if (pendingError) {
        dispatchError();
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:20,代码来源:FlashlightController.java


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