如何在Android设备上查找有关相机的技术数据?

时间:2014-01-08 10:39:15

标签: android camera

我想在Android设备上读出已安装摄像头的技术数据(例如:图像格式,分辨率,其他技术细节),因为我最终想要从摄像头捕获视频流然后进行后处理它(例如压缩+流动它)。所以我真的想知道相机返回什么样的视频/图像信号/格式,以便我可以使用它。

有没有办法做到这一点?我找到了getCameraInfo()方法,但这只是返回不那么有趣的信息。

2 个答案:

答案 0 :(得分:1)

您可以使用以下方法找到此类信息。

private static Map<String, String> getFullCameraParameters(Camera cam) {
    Map<String, String> result = new HashMap<String, String>(64);
    final String TAG = "Home";

    try {
        Class camClass = cam.getClass();

        // Internally, Android goes into native code to retrieve this String
        // of values
        Method getNativeParams = camClass
                .getDeclaredMethod("native_getParameters");
        getNativeParams.setAccessible(true);

        // Boom. Here's the raw String from the hardware
        String rawParamsStr = (String) getNativeParams.invoke(cam);

        // But let's do better. Here's what Android uses to parse the
        // String into a usable Map -- a simple ';' StringSplitter, followed
        // by splitting on '='
        //
        // Taken from Camera.Parameters unflatten() method
        TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(
                ';');
        splitter.setString(rawParamsStr);

        for (String kv : splitter) {
            int pos = kv.indexOf('=');
            if (pos == -1) {
                continue;
            }
            String k = kv.substring(0, pos);
            String v = kv.substring(pos + 1);
            result.put(k, v);
        }

        // And voila, you have a map of ALL supported parameters
        return result;
    } catch (NoSuchMethodException ex) {
        Log.e(TAG, ex.toString());
    } catch (IllegalAccessException ex) {
        Log.e(TAG, ex.toString());
    } catch (InvocationTargetException ex) {
        Log.e(TAG, ex.toString());
    }

    // If there was any error, just return an empty Map
    Log.e(TAG, "Unable to retrieve parameters from Camera.");
    return result;
}

要使用此方法,

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    camera = Camera.open();
    Map<String, String> info = getFullCameraParameters(camera);
}  

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    camera.release();
}

获取以下清单中的许可。

<uses-permission android:name="android.permission.CAMERA"/>

我在 info 对象中获得了以下信息。我实际上为它设置了一个调试点,然后获取以下信息。因为我不知道。 :)

{preferred-preview-size-for-video=176x144, zoom=0, mce=enable, hfr-size-values=, zoom-supported=true, strtextures=OFF, zsl-values=off,on, sharpness=10, hdr-values=, contrast=5, whitebalance=auto, max-sharpness=30, scene-mode=auto, jpeg-quality=85, preview-format-values=yuv420sp,yuv420p,yuv420p, rotation=0, histogram-values=, jpeg-thumbnail-quality=90, preview-format=yuv420sp, overlay-format=265, metering-areas=(-1000,-1000,1000,1000,1000), video-size-values=640x480,640x368,512x288,384x288,352x288,320x240,176x144, skinToneEnhancement=disable, preview-size=640x480, focal-length=1.15, auto-exposure-values=frame-average,center-weighted,spot-metering, video-zoom-support=false, iso=auto, denoise=denoise-off, mce-values=enable,disable, preview-frame-rate-values=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, power-mode-supported=false, max-num-metering-areas=1, semc-metering-mode=center-weighted, preview-frame-rate=30, focus-mode-values=infinity,fixed, jpeg-thumbnail-width=512, scene-mode-values=auto,night,snow,sports, preview-fps-range-values=(1000,15000),(1000,30000), auto-exposure=frame-average, jpeg-thumbnail-size-values=512x288,480x288,432x288,512x384,352x288,0x0, histogram=disable, zoom-ratios=100,102,104,107,109,112,114,117,120,123,125,128,131,135,138,141,144,148,151,155,158,162,166,170,174,178,182,186,190,195,200,204,209,214,219,224,229,235,240,246,251,257,263,270,276,282,289,296,303,310,317,324,332,340,348,356,364,373,381,390,400, camera-mode=0, preview-size-values=640x480,640x368,512x288,384x288,352x288,320x240,176x144, picture-size-values=2048x1536,1920x1080,1632x1224,1280x960,1280x720,640x480,320x240, touch-af-aec=touch-on, preview-fps-range=1000,30000, min-exposure-compensation=-6, antibanding=off, touch-af-aec-values=touch-off,touch-on, max-num-focus-areas=0, vertical-view-angle=42.5, luma-adaptation=3, horizontal-view-angle=54.8, jpeg-thumbnail-height=384, smooth-zoom-supported=true, focus-mode=fixed, max-saturation=10, semc-metering-mode-values=frame-average,center-weighted,spot, max-contrast=10, video-frame-format=yuv420sp, hdr=disable, picture-format-values=jpeg,raw, max-exposure-compensation=6, focus-areas=(-1000,-1000,1000,1000,1000), num-snaps-per-shutter=1, exposure-compensation=0, exposure-compensation-step=0.333333, scene-detect=off, picture-size=640x480, max-zoom=60, saturation=5, whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight, picture-format=jpeg, focus-distances=0.100000,0.150000,Infinity, zsl=off, touchAfAec-dx=100, lensshade-values=disable, touchAfAec-dy=100, iso-values=auto,ISO_HJR,ISO100,ISO200,ISO400,ISO800,ISO1600, lensshade=enable, antibanding-values=off,50hz,60hz,auto}

答案 1 :(得分:0)

Camera课程是您正在寻找的答案。此类提供了要在代码中实现的Camera API的所有详细信息。

  • Camera Tutorial
  • Camera Area Area类用于选择计算自动曝光,自动白平衡和自动对焦时相机的特定测光和对焦区域。
  • Camera Instance相机实例可用于计算3D变换并生成可应用于矩阵的矩阵。