本文介绍了如何获得相机RAW元数据信息的Andr​​oid编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,这台相机的硬件参数编程。

I have an app, which sets the hardware parameters of the Camera programmatically.

不过,正如有人告诉我,并前来观摩,并不是所有的芯片组支持的所有参数。

However, as I've been told, and have come to observe, not all chipsets support all parameters.

例如,Nexus的4(高通)的锐度和清晰度-MAX参数,Galaxy Note的II 3G没有任何

For example, the Nexus 4 (Qualcomm) has sharpness, and sharpness-max parameters, the Galaxy Note II 3g doesn't have any.

因此​​,当我设置锐度参数,Nexus的反应良好,但银河动力关闭:

Hence, when I set sharpness parameter, the Nexus responds well, but the Galaxy force closes:

java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1452)

我的问题是,我怎么能得到RAW信息编程?我需要得到的参数,他们的价值观,以及他们是否存在与否。

My question is, how can I get the RAW info programmatically? I need to get the parameters, their values, and whether they exist or not.

我希望得到的RAW-元数据参数,如下所示:数据库

I wish to get the RAW-Metadata parameters, as like this: database

推荐答案

好吧,认为这将是实践的一个有趣的一点。因此,Android不给一个公共的API到这个信息。为什么?我不知道。看起来你可以做一个 Camera.Parameters#GET(字符串)以检查你感兴趣的任何特定参数,但可以说你是贪婪和希望整个名单给自己。在这种情况下,我们可以使用反射潜水,但要注意的有一个很大的可能性,这将不会在Android所有版本的或在未来的版本可能会断裂。随着中说,这里是你如何做到这一点:

Alright, thought this would be a fun bit of practice. So, Android does not give a public API into this information. Why? I have no idea. Looks like you can do a Camera.Parameters#get(String) to check for any particular parameter that you're interested in, but lets say you're greedy and want the whole list to yourself. In that case, we can dive in using Reflection, but be aware that there is a strong possibility that this will not work on all versions of Android or may break in future versions. With that said, here's how you do it:

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

    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;
}

这篇关于如何获得相机RAW元数据信息的Andr​​oid编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:52