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


Java CameraManager.getCameraCharacteristics方法代码示例

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


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

示例1: onCreate

import android.hardware.camera2.CameraManager; //导入方法依赖的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

示例2: doesUserHaveFrontFacingCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Checks if user has front facing camera.
 * @param context Context used to check
 * @return 0 For front facing, 1 for back facing, -1 for if it does not have front facing at all
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static int doesUserHaveFrontFacingCamera(Context context) {

    if(Build.VERSION.SDK_INT >= 21) {
        try {
            CameraManager cManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
            for (int j = 0; j < cManager.getCameraIdList().length; j++) {
                String[] cameraId = cManager.getCameraIdList();
                CameraCharacteristics characteristics = cManager.getCameraCharacteristics(cameraId[j]);
                int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
                if (cOrientation == CameraCharacteristics.LENS_FACING_FRONT)
                    return j;
            }
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
    return -1; // No front-facing camera found
}
 
开发者ID:PGMacDesign,项目名称:PGMacTips,代码行数:25,代码来源:CameraMediaUtilities.java

示例3: open

import android.hardware.camera2.CameraManager; //导入方法依赖的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

示例4: getCameraInfo

import android.hardware.camera2.CameraManager; //导入方法依赖的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

示例5: isSupported

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Checks if API is supported and all cameras have better than legacy support.
 */
public static boolean isSupported(Context context) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    return false;
  }

  CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  try {
    String[] cameraIds = cameraManager.getCameraIdList();
    for (String id : cameraIds) {
      CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
      if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
          == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return false;
      }
    }
    // On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
    // catch statement with an Exception from a newer API, even if the code is never executed.
    // https://code.google.com/p/android/issues/detail?id=209129
  } catch (/* CameraAccessException */ AndroidException e) {
    Logging.e(TAG, "Camera access exception: " + e);
    return false;
  }
  return true;
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:28,代码来源:Camera2Enumerator.java

示例6: onImageAvailable

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
public void onImageAvailable(ImageReader reader)
{
    Activity activity = getActivity();

    if(null == mTextureView || null == mPreviewSize || null == activity)
    {
        return;
    }

    try
    {
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);

        mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(),
                getJpegOrientation(characteristics, rotation)));
    }
    catch(CameraAccessException e)
    {
        LogExt.e(getClass(), e);
    }
}
 
开发者ID:ResearchStack,项目名称:MoleMapperAndroid,代码行数:25,代码来源:LollipopCameraFragment.java

示例7: GetAllCameras2

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static List<MyCameraInfo> GetAllCameras2(Context context) throws Exception {
    List<MyCameraInfo> cameras = new ArrayList<>();

    CameraManager cameraManager =
            (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

    for (String cameraId : cameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        MyCameraInfo cameraInfo = MyCameraInfo.CreateFromCameraCharacteristics(cameraId,
                characteristics);
        cameras.add(cameraInfo);
    }

    return cameras;
}
 
开发者ID:tranquvis,项目名称:SimpleSmsRemote,代码行数:17,代码来源:CameraUtils.java

示例8: isFrontCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static  boolean isFrontCamera(Context ctx, String cameraId)
{

    boolean isFront = false;

    CameraManager manager = (CameraManager) ctx.getSystemService(Context.CAMERA_SERVICE);
    try
    {
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

        if (characteristics.get(CameraCharacteristics.LENS_FACING)
                == CameraCharacteristics.LENS_FACING_FRONT)
        {
            isFront = true;
        }

    } catch (CameraAccessException e)
    {
        LogHelper.logx(e);
    }

    return isFront;
}
 
开发者ID:joseliko7,项目名称:Snapmatic-Life,代码行数:25,代码来源:CameraHelper.java

示例9: scanCode

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void scanCode() {

    try {
        CameraManager manager = (CameraManager) getApplicationContext().getSystemService(Context.CAMERA_SERVICE);
        String[] cameraIds = manager.getCameraIdList();
        for (int i = 0; i < cameraIds.length; i++) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIds[i]);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
                IntentIntegrator integrator = new IntentIntegrator(this);
                integrator.setCameraId(i);
                integrator.initiateScan();
            }
        }
    } catch (CameraAccessException e) {
    }

}
 
开发者ID:wcomartin,项目名称:PlexPy-Remote,代码行数:19,代码来源:ServerQRScannerActivity.java

示例10: init

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.M)
public void init(Context context) {
    mContext = context;
    mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    
    try {
        for(final String cameraId : mCameraManager.getCameraIdList()){
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
            int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
            if(cOrientation == CameraCharacteristics.LENS_FACING_BACK){
                mCameraID= cameraId;
            }
        }
        
        
    } catch (CameraAccessException e) {
        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

}
 
开发者ID:SecUSo,项目名称:privacy-friendly-torchlight,代码行数:22,代码来源:CameraMarshmallow.java

示例11: camera2Id

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected String camera2Id(final int face)
//----------------------------------------
{
   try
   {
      CameraManager manager = (CameraManager) surfaceView.getContext().getSystemService(Context.CAMERA_SERVICE);
      String camList[] = manager.getCameraIdList();
      if (camList.length == 0)
         return null;
      CameraCharacteristics characteristics = null;
      for (String cameraID : camList)
      {
         characteristics = manager.getCameraCharacteristics(cameraID);
         Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
         if (facing == null) continue;
         if (face == facing)
            return cameraID;
      }
   }
   catch (Exception e)
   {
      return null;
   }
   return null;
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:27,代码来源:LegacyPreviewCamera.java

示例12: hasCamera2

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean hasCamera2(Context context) {
    if (context == null) return false;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false;
    try {
        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
        String[] idList = manager.getCameraIdList();
        boolean notNull = true;
        if (idList.length == 0) {
            notNull = false;
        } else {
            for (final String str : idList) {
                if (str == null || str.trim().isEmpty()) {
                    notNull = false;
                    break;
                }
                final CameraCharacteristics characteristics = manager.getCameraCharacteristics(str);

                final int supportLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
                if (supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
                    notNull = false;
                    break;
                }
            }
        }
        return notNull;
    } catch (Throwable ignore) {
        return false;
    }
}
 
开发者ID:florent37,项目名称:CameraFragment,代码行数:31,代码来源:CameraHelper.java

示例13: chooseCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private String chooseCamera() {
  final CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
  try {
    for (final String cameraId : manager.getCameraIdList()) {
      final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

      // We don't use a front facing camera in this sample.
      final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
      if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
        continue;
      }

      final StreamConfigurationMap map =
          characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

      if (map == null) {
        continue;
      }

      useCamera2API = isHardwareLevelSupported(characteristics,
          CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
      LOGGER.i("Camera API lv2?: %s", useCamera2API);
      return cameraId;
    }
  } catch (CameraAccessException e) {
    LOGGER.e(e, "Not allowed to access camera");
  }

  return null;
}
 
开发者ID:Nilhcem,项目名称:tensorflow-classifier-android,代码行数:31,代码来源:CameraActivity.java

示例14: isCamera2Native

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
public boolean isCamera2Native() {
    try {
        if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {return false;}
        manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //CHECK CAMERA HARDWARE LEVEL. IF CAMERA2 IS NOT NATIVELY SUPPORTED, GO BACK TO CAMERA1
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return deviceLevel != null && (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
    }
    catch (CameraAccessException ex) {return false;}
    catch (NullPointerException e) {return false;}
    catch (ArrayIndexOutOfBoundsException ez) {return false;}
}
 
开发者ID:EzequielAdrianM,项目名称:Camera2Vision,代码行数:15,代码来源:Camera2Source.java

示例15: triggerFocusArea

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void triggerFocusArea(float x, float y) {
    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics characteristics
                = manager.getCameraCharacteristics(mCameraId);
        Integer sensorOrientation = characteristics.get(
                CameraCharacteristics.SENSOR_ORIENTATION);

        sensorOrientation = sensorOrientation == null ? 0 : sensorOrientation;

        Rect cropRegion = AutoFocusHelper.cropRegionForZoom(characteristics, 1f);
        mAERegions = AutoFocusHelper.aeRegionsForNormalizedCoord(x, y, cropRegion, sensorOrientation);
        mAFRegions = AutoFocusHelper.afRegionsForNormalizedCoord(x, y, cropRegion, sensorOrientation);

        // Step 1: Request single frame CONTROL_AF_TRIGGER_START.
        CaptureRequest.Builder builder;
        builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        builder.addTarget(mPreviewSurface);
        builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

        mControlAFMode = AutoFocusMode.AUTO;

        builder.set(CaptureRequest.CONTROL_AF_MODE, mControlAFMode.switchToCamera2FocusMode());
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
        mCaptureSession.capture(builder.build(), mPreCaptureCallback, mBackgroundHandler);

        // Step 2: Call repeatingPreview to update mControlAFMode.
        sendRepeatPreviewRequest();
        resumeContinuousAFAfterDelay(DELAY_TIME_RESUME_CONTINUOUS_AF);
    } catch (CameraAccessException ex) {
        Log.e(TAG, "Could not execute preview request.", ex);
    }
}
 
开发者ID:gengqifu,项目名称:361Camera,代码行数:34,代码来源:Camera2Fragment.java


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