首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android设备上找到有关摄像头的技术数据?

如何在Android设备上找到有关摄像头的技术数据?
EN

Stack Overflow用户
提问于 2014-01-08 10:39:14
回答 1查看 792关注 0票数 0

我想读出Android设备上安装的摄像机的技术数据(例如:图像格式、分辨率、其他技术细节),因为我最终希望从摄像机中捕获视频流,然后对其进行后处理(例如,压缩+流)。所以我真的很想知道摄像机返回的是什么样的视频/图片信号/格式,这样我就可以使用它了。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-08 11:09:20

您可以通过以下方法找到这样的信息。

代码语言:javascript
复制
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;
}

要使用这种方法,

代码语言:javascript
复制
@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();
}

在下面这样的清单中获得许可。

代码语言:javascript
复制
<uses-permission android:name="android.permission.CAMERA"/>

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

{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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20993189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档