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


Java CameraCharacteristics類代碼示例

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


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

示例1: collectCameraInfo

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
/**
 * <p>Collects some information from {@link #mCameraCharacteristics}.</p>
 * <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
 * {@link #mAspectRatio}.</p>
 */
private void collectCameraInfo() {
    StreamConfigurationMap map = mCameraCharacteristics.get(
            CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    if (map == null) {
        throw new IllegalStateException("Failed to get configuration map: " + mCameraId);
    }
    mPreviewSizes.clear();
    for (android.util.Size size : map.getOutputSizes(mPreview.getOutputClass())) {
        mPreviewSizes.add(new Size(size.getWidth(), size.getHeight()));
    }
    mPictureSizes.clear();
    collectPictureSizes(mPictureSizes, map);

    if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
        mAspectRatio = mPreviewSizes.ratios().iterator().next();
    }
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:23,代碼來源:Camera2.java

示例2: onCreate

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_v2);

    CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
    try {
        for (String cameraId : cameraManager.getCameraIdList()) {
            CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing.equals(CameraCharacteristics.LENS_FACING_FRONT)) {

            }
            // Do something with the characteristics
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:akexorcist,項目名稱:CameraSample,代碼行數:20,代碼來源:CameraV2Activity.java

示例3: onStopTrackingTouch

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    switch (seekBar.getId()) {
        case R.id.iso: {
            Range<Integer> range = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE);
            int max = range.getUpper();
            int min = range.getLower();
            isoValue = ((seekBar.getProgress() * (max - min)) / 100 + min);
            createCameraPreviewSession_ISO();
            break;
        }
        case R.id.focus: {
            float distance = mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
            focusValue = seekBar.getProgress() * distance / 100;
            createCameraPreviewSession_FOCUS();
            break;
        }
        default:
            break;
    }

}
 
開發者ID:wingskyer,項目名稱:android-Camera2Basic-master,代碼行數:23,代碼來源:Camera2BasicFragment.java

示例4: logSupportedHardwareLevel

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
private void logSupportedHardwareLevel(@NonNull String cameraId) {
    int hardwareLevel = cameraCharacteristicsHelper.getSupportedHardwareLevel(cameraId);

    String hardwareLevelName = String.valueOf(hardwareLevel);  // for level 3 and higher
    switch (hardwareLevel) {
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            hardwareLevelName = "legacy";
            break;
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            hardwareLevelName = "limited";
            break;
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
            hardwareLevelName = "full";
            break;
    }

    log.d("using camera with supported hardware level: %s", hardwareLevelName);
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:19,代碼來源:CameraHelper.java

示例5: open

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
public void open() {
    try {
        CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
                StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                mCameraSize = map.getOutputSizes(SurfaceTexture.class)[0];

                HandlerThread thread = new HandlerThread("OpenCamera");
                thread.start();
                Handler backgroundHandler = new Handler(thread.getLooper());

                manager.openCamera(cameraId, mCameraDeviceCallback, null);

                // カメラの物理的な情報を得る
                mCameraCharacteristics = manager.getCameraCharacteristics( cameraId );
                return;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:jphacks,項目名稱:TK_1701,代碼行數:25,代碼來源:Camera2.java

示例6: updateAutoFocus

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
/**
 * Updates the internal state of auto-focus to {@link #mAutoFocus}.
 */
void updateAutoFocus() {
    if (mAutoFocus) {
        int[] modes = mCameraCharacteristics.get(
                CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
        // Auto focus is not supported
        if (modes == null || modes.length == 0 ||
                (modes.length == 1 && modes[0] == CameraCharacteristics.CONTROL_AF_MODE_OFF)) {
            mAutoFocus = false;
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_OFF);
        } else {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        }
    } else {
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_OFF);
    }
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:23,代碼來源:Camera2.java

示例7: needSwappedDimensions

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
/**
 * Find out if we need to swap dimensions to get the preview size relative to sensor coordinate.
 * @param activity - The associated activity from which the camera is loaded.
 * @param characteristics - CameraCharacteristics corresponding to the current started cameradevice
 * @return swappedDimensions - A boolean value indicating if the the dimensions need to be swapped.
 */
public static boolean needSwappedDimensions(Activity activity, CameraCharacteristics characteristics) {
    int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    //noinspection ConstantConditions
    int mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    boolean swappedDimensions = false;
    switch (displayRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_90:
            if (mSensorOrientation == 90 || mSensorOrientation == 270) {
                swappedDimensions = true;
            }
            break;
        case Surface.ROTATION_180:
        case Surface.ROTATION_270:
            if (mSensorOrientation == 0 || mSensorOrientation == 180) {
                swappedDimensions = true;
            }
            break;
        default:
            Log.e(TAG, "Display rotation is invalid: " + displayRotation);
    }
    return swappedDimensions;
}
 
開發者ID:digital-voting-pass,項目名稱:polling-station-app,代碼行數:30,代碼來源:CameraFragmentUtil.java

示例8: createCamera

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Override
protected String createCamera(int deviceDegrees) throws CameraException {
    try {
        for (String camId : mCamManager.getCameraIdList()) {
            CameraCharacteristics characteristics = mCamManager.getCameraCharacteristics(camId);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

            if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
                Log.d(TAG, "front-facing mCamera found: " + camId);
                return camId;
            }
        }
    } catch (CameraAccessException e) {
        throw new CameraException(e);
    }

    throw new CameraException(mActivity.getString(R.string.frontCameraMissing));
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:19,代碼來源:MotionDetectorCamera2.java

示例9: getCameraInfo

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Override
protected String getCameraInfo() {
    String camStr = mContext.getString(R.string.camApi2) + "\n";
    CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String camId : camManager.getCameraIdList()) {
            camStr += mContext.getString(R.string.cameraId, camId) + ": ";

            CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
            Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

            camStr += (hasFlash ? mContext.getString(R.string.has) : mContext.getString(R.string.no))
                    + " " + mContext.getString(R.string.flash) + ", ";
            camStr += (facing == CameraCharacteristics.LENS_FACING_BACK ?
                    mContext.getString(R.string.backFacing) : mContext.getString(R.string.frontFacing)) + "\n";
        }
    } catch (CameraAccessException e) {
        camStr = mActivity.getString(R.string.failedAccessCamera) + ":" + e.getMessage();
    }

    return camStr.trim();
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:24,代碼來源:MotionDetectorCamera2.java

示例10: FlashController

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
public FlashController(Context ctx, CameraManager cameraManager, ServerConnection serverConnection) throws CameraAccessException, IllegalAccessException {
    mCtx = ctx;
    camManager = cameraManager;
    mServerConnection = serverConnection;

    EventBus.getDefault().register(this);

    for (String camId : camManager.getCameraIdList()) {
        CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
        Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

        if (facing == CameraCharacteristics.LENS_FACING_BACK && hasFlash) {
            torchId = camId;
            break;
        }
    }

    if (torchId == null) {
        throw new IllegalAccessException(ctx.getString(R.string.couldNotFindBackFlash));
    }
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:23,代碼來源:FlashController.java

示例11: collectRatioSizes

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Override
public void collectRatioSizes() {
    ratioSizeList.clear();
    CameraCharacteristics characteristics;
    StreamConfigurationMap map = null;
    try {
        characteristics = ((CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE)).getCameraCharacteristics(Integer.toString(Integer.parseInt(getCameraId())));
        map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

    Size[] outputSizes = map.getOutputSizes(SurfaceTexture.class);
    if (outputSizes != null) {
        List<Double> ratioList = new ArrayList<>();
        for (Size size : outputSizes) {
            double ratio = (double) size.getWidth() / (double) size.getHeight();
            if (!ratioList.contains(ratio)) {
                ratioList.add(ratio);
                ratioSizeList.add(new AspectRatio(ratio, size.getWidth(), size.getHeight()));
            }
        }
    }
}
 
開發者ID:team-supercharge,項目名稱:SCCameraView,代碼行數:25,代碼來源:Camera2View.java

示例12: sensorToDeviceRotation

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
/**
 * Rotation need to transform from the camera sensor orientation to the device's current
 * orientation.
 *
 * @param c                 the {@link CameraCharacteristics} to query for the camera sensor
 *                          orientation.
 * @param deviceOrientation the current device orientation relative to the native device
 *                          orientation.
 * @return the total rotation from the sensor orientation to the current device orientation.
 */
private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Get device orientation in degrees
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);

    // Reverse device orientation for front-facing cameras
    if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
        deviceOrientation = -deviceOrientation;
    }

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    return (sensorOrientation + deviceOrientation + 360) % 360;
}
 
開發者ID:gengqifu,項目名稱:361Camera,代碼行數:26,代碼來源:Camera2Fragment.java

示例13: getOrThrow

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@NonNull
private <T> T getOrThrow(@NonNull String cameraId, @NonNull CameraCharacteristics.Key<T> key) {
    try {
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

        T value = characteristics.get(key);

        if (value == null) {
            throw new CameraException("could not determine camera characteristic " + key.getName() + " from camera " + cameraId);
        } else {
            return value;
        }
    } catch (CameraAccessException e) {
        throw new CameraException(e);
    }
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:17,代碼來源:CameraCharacteristicsHelper.java

示例14: setUp

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    surfaces = asList(surface1, surface2);

    when(manager.getCameraIdList()).thenReturn(new String[]{CAMERA_ID_1, CAMERA_ID_2});

    when(characteristicsHelper.getLensFacing(CAMERA_ID_1)).thenReturn(CameraCharacteristics.LENS_FACING_BACK);
    when(characteristicsHelper.getLensFacing(CAMERA_ID_2)).thenReturn(CameraCharacteristics.LENS_FACING_FRONT);
    when(characteristicsHelper.getSensorOrientation(CAMERA_ID_1)).thenReturn(SENSOR_ROTATION);
    when(characteristicsHelper.getPreviewOutputSizes(CAMERA_ID_1)).thenReturn(
            new Size[]{PREVIEWSIZE_1, PREVIEWSIZE_640x480, PREVIEWSIZE_2});

    when(camera.getId()).thenReturn(CAMERA_ID_1);
    when(camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)).thenReturn(captureRequestBuilder);

    when(textureView.getSurfaceTexture()).thenReturn(surfaceTexture);
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:18,代碼來源:CameraHelperTest.java

示例15: sensorToDeviceRotation

import android.hardware.camera2.CameraCharacteristics; //導入依賴的package包/類
/**
 * Rotation need to transform from the camera sensor orientation to the device's current
 * orientation.
 *
 * @param c                 the {@link CameraCharacteristics} to query for the camera sensor
 *                          orientation.
 * @param deviceOrientation the current device orientation relative to the native device
 *                          orientation.
 * @return the total rotation from the sensor orientation to the current device orientation.
 */
public static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Get device orientation in degrees
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);

    // Reverse device orientation for front-facing cameras
    if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
        deviceOrientation = -deviceOrientation;
    }

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    return (sensorOrientation + deviceOrientation + 360) % 360;
}
 
開發者ID:OkayCamera,項目名稱:OkayCamera-Android,代碼行數:26,代碼來源:Utils.java


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