Android camera supported picture sizes

前端 未结 4 1231
难免孤独
难免孤独 2020-12-14 20:32

I am trying to retrieve the available camera image sizes, so I able to adjust the camera to my preferred image resolution.

To retrieve the Android camera size I\'ve

相关标签:
4条回答
  • 2020-12-14 20:52

    getSupportedPictureSizes() returns a List of Camera.Size objects. Camera.Size has height and width data members that tell you the height and width of the supported picture size.

    Here is a sample project that uses the related getSupportedPreviewSizes() to find the preview size with the largest area that is smaller than the SurfaceView's size.

    0 讨论(0)
  • 2020-12-14 20:55
    Camera camera = Camera.open();
    Parameters params = camera.getParameters();
    List sizes = params.getSupportedPictureSizes();
    for (int i=0;i<sizes.size();i++) {
        Log.i("PictureSize", "Supported Size: " +sizes.get(i).width + "height : " + sizes.get(i).height);     
    }   
    

    You have to take height and width from one size object

    0 讨论(0)
  • 2020-12-14 21:01

    This is what I ended up doing. Since the method params.getSupportedPictureSizes() returns a list of type Camera.Size, it was easy to do this:

            List<Camera.Size> sizes = p.getSupportedPictureSizes();
    
            //searches for good picture quality
            for(Camera.Size dimens : sizes){
                if(dimens.width  <= 1024 && dimens.height <= 768){
                    Debug.WriteLine("Width: " + dimens.width + " Height: " + dimens.height);
                    return dimens;
                }
            }
    
            Debug.WriteLine("Width: " + sizes.get(sizes.size()-1).width + " Height: " + sizes.get(sizes.size()-1).height);
            //returns the smallest camera size if worst comes to worst
            return p.getSupportedPictureSizes().get(sizes.size()-1);
    

    You can get a List<Camera.Size> and traverse it like any other list. the Camera.Size object has a width and height property.

    Declaring your Listthis way might be better than casting each element of the list to type Camera.Size inside of a loop.

    On my devices, if I look at sizes.get(0), it will have the highest resolution while sizes.get( sizes.size()-1 ) has the lowest. I'm not sure if this is true across all devices, however. Anyone have insight on that?

    0 讨论(0)
  • 2020-12-14 21:16

    Here is a example of how to search for the size that is aprroaching your max size (1024 * 768) for example.

                    List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
                    //searches for good picture quality
                    Camera.Size bestDimens = null;
                    for(Camera.Size dimens : sizes){
                        if(dimens.width  <= 1024 && dimens.height <= 768){
                            if (bestDimens == null || (dimens.width > bestDimens.width && dimens.height > bestDimens.height)) {
                                bestDimens = dimens;
                            }
                        }
                    }
                    parameters.setPictureSize(bestDimens.width, bestDimens.height);
                    camera.setParameters(parameters);
    
    0 讨论(0)
提交回复
热议问题