Android Camera2 API显示相机特性

时间:2016-10-06 05:49:13

标签: c# android xamarin camera2

我不习惯C#/移动编程/ Xamarin,所以请不要因为我的愚蠢错误而责备我。 我正在尝试制作一个能显示我的设备相机功能的程序。以下是代码示例:

TextView a = new TextView (this);
A = Java.Lang.Integer ((int)CameraCharacteristics.ColorCorrectionAvailableAberrationModes);

错误:

"CameraCharacteristics.ColorCorrectionAvailableAberrationModes must declare a body because it is not marked abstract extern or partial"

我该怎么办?

1 个答案:

答案 0 :(得分:1)

以下是java中用于打印少量camera2 Api特征的代码。您可以使用相同的概念并尝试在c#中实现。这可能不是有效的代码,但可以满足您的目的。

有些特性在某些手机中不起作用,因此它取决于您使用的手机进行测试。我尝试使用Nexus 5和联想手机。

流配置地图特征。从link

开始
private void setupCamera(int width, int height) {
 CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        for(String cameraId: cameraManager.getCameraIdList()) {
            CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
            if(cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }
            StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

//GET OUTPUT SIZES
mOutputsize = map.getOutputSizes(SurfaceTexture.class);
for(int i=0; i<mOutputsize.length; i++) {
    Log.d("OUTPUT SIZES", String.valueOf(mOutputsize[i]));
}

//GET HIGH SPEED VIDEO SIZE
//All the sizes listed in this method are the subset of getOutputSizes(int) method
 mHighSpeedVideoSize = map.getHighSpeedVideoSizes();
 for(int j=0; j<mHighSpeedVideoSize.length; j++) {
      Log.d("OUTPUT SIZES", "High speed video sizes");
      Log.d("OUTPUT SIZES", mHighSpeedVideoSize[j].toString());
 }

//GET THE IMAGE OUTPUT FORMAT (make sure you check if the array is pointing is null or not, otherwise you will have null point exception. The best way is to comment and see one by one)
 mOutputFormat = map.getOutputFormats();
 Log.d("OUTPUT SIZES", "Image Output Format: ");
 Log.d("OUTPUT SIZES", "Image.format = RAW_SENSOR, Constant Value: 32 (0x00000020) " + String.valueOf(mOutputFormat[0]));
 Log.d("OUTPUT SIZES", "Image.format = JPEG, Constant Value: 256 (0x00000100) " + String.valueOf(mOutputFormat[1]));
 Log.d("OUTPUT SIZES", "Image.format = PRIVATE, Constant Value: 34 (0x00000022) " + String.valueOf(mOutputFormat[2]));
 Log.d("OUTPUT SIZES", "Image.format = YUV_420_888, Constant Value: 35 (0x00000023) " + String.valueOf(mOutputFormat[3]));

我甚至试图从这个link打印出一些特征。这是:

//COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES
  int[] aberration = cameraCharacteristics.get(CameraCharacteristics.COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES);
  String str2;
  for(int i=0; i<aberration.length; i++) {
       str2 = String.valueOf(aberration[i]);
       Log.d("OUTPUT SIZES ABR ", str2);
    }
       Log.d("OUTPUT SIZES Length: ", String.valueOf(aberration.length));

//CONTROL_AE_COMPENSATION_RANGE
 Range<Integer> exposureRange = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
 String maxRange = String.valueOf(exposureRange);
 Log.d("OUTPUT SIZES EXPO range", maxRange + "\n");

//CONTROL_AE_COMPENSATION_STEP
  Rational step = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
  Log.d("OUTPUT SIZE COMP step", String.valueOf(step));


//CONTROL_AE_LOCK_AVAILABLE
  boolean lock = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_LOCK_AVAILABLE);
  Log.d("OUTPUT SIZES LOCK avai", String.valueOf(lock));


 //CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES
  int[] videoStabilizationModes = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES);
   for(int i=0; i<videoStabilizationModes.length; i++) {
       Log.d("OUTPUT SIZES STABI mode", String.valueOf(videoStabilizationModes[i]));
    }

 //CONTROL_MAX_REGIONS_AWB
   Integer regionsAWB = cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AWB);
   Log.d("OUTPUT SIZES REGION AWB", String.valueOf(regionsAWB));

 //JPEG_AVAILABLE_THUMBNAIL_SIZES
  Size[] jpegThumbnail = cameraCharacteristics.get(CameraCharacteristics.JPEG_AVAILABLE_THUMBNAIL_SIZES);
  for(int i=0; i<jpegThumbnail.length; i++) {
  Log.d("OUTPUT SIZES JPEG THUMB", String.valueOf(jpegThumbnail[i]));
  }


 //SENSOR_BLACK_LEVEL_PATTERN
  BlackLevelPattern blackLevelPattern = cameraCharacteristics.get(CameraCharacteristics.SENSOR_BLACK_LEVEL_PATTERN);
  Log.d("OUTPUT SIZES BLCK PTRN", String.valueOf(blackLevelPattern));


   mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

}

PS:这不是完整的代码。这是我为相机应用程序编写的代码中的代码片段。我想你只需要知道这些特征。我在代码中使用了一些变量但未在此答案中声明。我认为你现在不需要这些信息。 快乐的编码:)