當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。