English 中文(简体)
摄像机,在银河塔的回报无效。
原标题:Camera.getParameters() return null on Galaxy Tab

这里是我的地面变化活动处理守则:

    public void surfaceChanged(SurfaceHolder holder,
                               int format, int width,
                               int height) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = getBestPreviewSize(width, height,
                parameters);
       //...
    }


    private Camera.Size getBestPreviewSize(int width, int height,
                                       Camera.Parameters parameters) {
        Camera.Size result = null;

        // it fails with NullPointerExceptiopn here,
        // when accessing "getSupportedPreviewSizes" method:
        // that means "parameters" is null
        for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
            ///...
        }
    }

我开始照相机。

    @Override
    public void onResume() {
        super.onResume();
        camera = Camera.open();
    }

这个问题在我的银河S Plus上没有发生,也没有出现在LG Bestus Black电话上。 是否有任何人认为这里有什么错误?

最佳回答

页: 1

parameters.getSupportedPreviewSizes()

Backs NUL on银河塔。 因此,我只作一次检查,看看它是否无效,没有在这种情况下确定新的审查规模。 我在研究了标准摄像机应用来源后得出这一结论。

问题回答

: >;<>>;<>>>;>;>;>;>;>;>;>;>;>;。

camera initialization depends a lot on the specific device. For instance a specific Samsung device GT5500 is reporting null (width = 0, height = 0) as a valid resolution for preview, but crashes the whole phone ("hard" reboot) if you try to use it. We experienced it with mixare augmented reality engine (http://www.mixare.org) and it was PITA to debug (since we didn t have the phone and could not reproduce the bug on any other hardware).

然而,在达到“权利”审查规模时,你可以研究一下我们关于兴奋剂的法典(它是一个自由和开放的来源)。 在档案中:https://github.com/mixare/mixare/blobmaster/src/org/mixare/MixView.java (第871及以后各段)

        List<Camera.Size> supportedSizes = null;
        //On older devices (<1.6) the following will fail
        //the camera will work nevertheless
        supportedSizes = Compatibility.getSupportedPreviewSizes(parameters);

        //preview form factor
        float ff = (float)w/h;
        Log.d("Mixare", "Screen res: w:"+ w + " h:" + h + " aspect ratio:" + ff);

        //holder for the best form factor and size
        float bff = 0;
        int bestw = 0;
        int besth = 0;
        Iterator<Camera.Size> itr = supportedSizes.iterator();

        //we look for the best preview size, it has to be the closest to the
        //screen form factor, and be less wide than the screen itself
        //the latter requirement is because the HTC Hero with update 2.1 will
        //report camera preview sizes larger than the screen, and it will fail
        //to initialize the camera
        //other devices could work with previews larger than the screen though
        while(itr.hasNext()) {
            Camera.Size element = itr.next();
            //current form factor
            float cff = (float)element.width/element.height;
            //check if the current element is a candidate to replace the best match so far
            //current form factor should be closer to the bff
            //preview width should be less than screen width
            //preview width should be more than current bestw
            //this combination will ensure that the highest resolution will win
            Log.d("Mixare", "Candidate camera element: w:"+ element.width + " h:" + element.height + " aspect ratio:" + cff);
            if ((ff-cff <= ff-bff) && (element.width <= w) && (element.width >= bestw)) {
                bff=cff;
                bestw = element.width;
                besth = element.height;
            }
        } 
        Log.d("Mixare", "Chosen camera element: w:"+ bestw + " h:" + besth + " aspect ratio:" + bff);
        //Some Samsung phones will end up with bestw and besth = 0 because their minimum preview size is bigger then the screen size.
        //In this case, we use the default values: 480x320
        if ((bestw == 0) || (besth == 0)){
            Log.d("Mixare", "Using default camera parameters!");
            bestw = 480;
            besth = 320;
        }
        parameters.setPreviewSize(bestw, besth);

你们看到,我们没有直接使用要求获得照相机组的辅助性审查,而是增加了相容层(此代码是:,因为我们需要与旧电话相容。 如果你不希望支持老年和roid释放,你可以直接使用照相机组的方法。

HTH Daniele





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签