當前位置: 首頁>>代碼示例>>Java>>正文


Java CameraDevice類代碼示例

本文整理匯總了Java中android.hardware.camera2.CameraDevice的典型用法代碼示例。如果您正苦於以下問題:Java CameraDevice類的具體用法?Java CameraDevice怎麽用?Java CameraDevice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CameraDevice類屬於android.hardware.camera2包,在下文中一共展示了CameraDevice類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupCaptureRequestForPreview

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
/**
 * does setup the repeating capture request for taking images for the preview
 */
@VisibleForTesting
void setupCaptureRequestForPreview(@NonNull CameraCaptureSession previewSession, @NonNull CameraDevice camera,
                                   @NonNull List<Surface> surfaces) {
    try {
        CaptureRequest.Builder previewRequestBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        for (Surface surface : surfaces) {
            previewRequestBuilder.addTarget(surface);
        }
        previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

        previewSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);

    } catch (CameraAccessException | IllegalStateException e) {
        throw new CameraException(e);
    }
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:20,代碼來源:CameraHelper.java

示例2: startPreview

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private void startPreview() {
    try {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

        Size previewSize = Util.getPreferredPreviewSize(
                configMap.getOutputSizes(ImageFormat.JPEG),textureView.getWidth(), textureView.getHeight());

        surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
        Surface surface = new Surface(surfaceTexture);
        captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        captureBuilder.addTarget(surface);

        cameraDevice.createCaptureSession(Arrays.asList(surface),captureSessionCallback,backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:lazyparser,項目名稱:xbot_head,代碼行數:19,代碼來源:CommentaryFragment.java

示例3: createCameraPreviewSession

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private void createCameraPreviewSession() {
        if (mCamera == null) {
            return;
        }


        SurfaceHolder holder = surfaceView.getHolder();
//        if (config != null) {
//            holder.setFixedSize(640, 480);
//        }
        Surface surface = holder.getSurface();


        List<Surface> surfaceList = Arrays.asList(surface, mImageReader.getSurface());

        try {
            mPreviewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            mPreviewBuilder.addTarget(surface);

            mCamera.createCaptureSession(surfaceList, sessionCallback, mHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:ThinkKeep,項目名稱:EvilsLive,代碼行數:25,代碼來源:CameraNew.java

示例4: onOpened

import android.hardware.camera2.CameraDevice; //導入依賴的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,項目名稱:VideoCRE,代碼行數:24,代碼來源:Camera2Session.java

示例5: getErrorDescription

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private String getErrorDescription(int errorCode) {
  switch (errorCode) {
    case CameraDevice.StateCallback.ERROR_CAMERA_DEVICE:
      return "Camera device has encountered a fatal error.";
    case CameraDevice.StateCallback.ERROR_CAMERA_DISABLED:
      return "Camera device could not be opened due to a device policy.";
    case CameraDevice.StateCallback.ERROR_CAMERA_IN_USE:
      return "Camera device is in use already.";
    case CameraDevice.StateCallback.ERROR_CAMERA_SERVICE:
      return "Camera service has encountered a fatal error.";
    case CameraDevice.StateCallback.ERROR_MAX_CAMERAS_IN_USE:
      return "Camera device could not be opened because"
          + " there are too many other open camera devices.";
    default:
      return "Unknown camera error: " + errorCode;
  }
}
 
開發者ID:Piasy,項目名稱:VideoCRE,代碼行數:18,代碼來源:Camera2Session.java

示例6: onClosed

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onClosed(CameraDevice cameraDevice) {
  Logging.d(TAG, "Simple camera2 closed.");

  synchronized (cameraDeviceLock) {
    SimpleCamera2.this.cameraDevice = null;
  }
}
 
開發者ID:lgyjg,項目名稱:AndroidRTC,代碼行數:9,代碼來源:Camera2CapturerTest.java

示例7: onOpened

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(final CameraDevice cd) {
    // This method is called when the camera is opened.  We start camera preview here.
    cameraOpenCloseLock.release();
    cameraDevice = cd;
    createCameraPreviewSession();
}
 
開發者ID:SimonCherryGZ,項目名稱:face-landmark-android,代碼行數:8,代碼來源:ARMaskFragment.java

示例8: onOpened

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(@NonNull CameraDevice cameraDevice) {
    // This method is called when the camera is opened.  We start camera preview here.
    mCameraOpenCloseLock.release();
    mCameraDevice = cameraDevice;
    createCameraPreviewSession();
}
 
開發者ID:vulovicv23,項目名稱:opencv-documentscanner-android,代碼行數:8,代碼來源:Camera2BasicFragment.java

示例9: onError

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onError(@NonNull CameraDevice cameraDevice, int error) {
    mCameraOpenCloseLock.release();
    cameraDevice.close();
    mCameraDevice = null;
    Activity activity = getActivity();
    if (null != activity) {
        activity.finish();
    }
}
 
開發者ID:vulovicv23,項目名稱:opencv-documentscanner-android,代碼行數:11,代碼來源:Camera2BasicFragment.java

示例10: onClosed

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onClosed(@NonNull CameraDevice camera) {
    cameraClosed = true;
    Log.d(TAG, "camera " + camera.getId() + " closed");
    //once the current camera has been closed, start taking another picture
    if (!cameraIds.isEmpty()) {
        takeAnotherPicture();
    } else {
        capturingListener.onDoneCapturingAllPhotos(picturesTaken);
    }
}
 
開發者ID:botyourbusiness,項目名稱:android-camera2-secret-picture-taker,代碼行數:12,代碼來源:PictureCapturingServiceImpl.java

示例11: triggerImageCapture

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
/**
 * Execute a new capture request within the active session
 */
private void triggerImageCapture() {
    try {
        final CaptureRequest.Builder captureBuilder =
                mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
        Log.d(TAG, "Capture request created.");
        mCaptureSession.capture(captureBuilder.build(), mCaptureCallback, null);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "camera capture exception");
    } catch (IllegalStateException e) {
        Log.d(TAG, "camera freaked out");
    }
}
 
開發者ID:Deeplocal,項目名稱:android-things-drawbot,代碼行數:18,代碼來源:CameraHandler.java

示例12: onOpened

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(final CameraDevice cd) {
  // This method is called when the camera is opened.  We start camera preview here.
  cameraOpenCloseLock.release();
  cameraDevice = cd;
  createCameraPreviewSession();
}
 
開發者ID:PallabPaul,項目名稱:AI_Calorie_Counter_Demo,代碼行數:8,代碼來源:CameraConnectionFragment.java

示例13: captureStillPicture

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 */
private void captureStillPicture() {
    try {
        if (null == mCameraDevice) {
            return;
        }
        if(mShutterCallback != null) {
            mShutterCallback.onShutter();
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReaderStill.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, mFocusMode);
        if(mFlashSupported) {
            captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
        }

        // Orientation
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(mDisplayOrientation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:EzequielAdrianM,項目名稱:Camera2Vision,代碼行數:40,代碼來源:Camera2Source.java

示例14: onOpened

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(CameraDevice cameraDevice) {
    Camera2Manager.this.cameraDevice = cameraDevice;
    if (cameraOpenListener != null) {
        uiHandler.post(new Runnable() {
            @Override
            public void run() {
                if (!TextUtils.isEmpty(currentCameraId) && previewSize != null)
                    cameraOpenListener.onCameraOpened(currentCameraId, previewSize, Camera2Manager.this);
            }
        });
    }
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:14,代碼來源:Camera2Manager.java

示例15: onDisconnected

import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onDisconnected(CameraDevice cameraDevice) {
    cameraDevice.close();
    Camera2Manager.this.cameraDevice = null;

    uiHandler.post(new Runnable() {
        @Override
        public void run() {
            cameraOpenListener.onCameraOpenError();
        }
    });
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:13,代碼來源:Camera2Manager.java


注:本文中的android.hardware.camera2.CameraDevice類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。