本文介绍了如何获得设备的真实Camera max Megapixels?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找设备的REAL Camera最大百万像素,并且我使用cam.getParameters().getSupportedPictureSizes();测试了stackoverflow和google上找到的一些代码,但是该代码在所有设备上均无法正常工作.

I'm trying to find the REAL Camera max Megapixels of a device and i tested some code found on stackoverflow and google with cam.getParameters().getSupportedPictureSizes();, but the code does not work well on all the devices.

例如,在NEXUS 5上,它工作正常,并告诉该设备具有8Mpx,但是在带有KitKat 4.4.2的BQ Aquaris E5 FHD中,它不能很好地工作,并告诉该设备具有19 Mpx(其具有13 Mpx. )

For example on NEXUS 5 it works fine and tells that the device haves 8Mpx, but in BQ Aquaris E5 FHD with KitKat 4.4.2 it does not work well and tells that the device haves 19 Mpx (it haves 13 Mpx...)

Bq​​ Aquaris中的问题是代码获得了所有受支持的图片大小,并且最大的值是5888x3312,该值表示19.5 mpx,但实际上此设备不支持19.5 mpx,所以我不明白为什么5888x3312是被getSupportedPictureSizes()破坏,我不知道该如何忽略诸如该值之类的非真实值.

The problem in Bq Aquaris is that the code obtains all the supported picture sizes, and the most huge value is 5888x3312, that value means 19.5 mpx, but really this device does not support 19.5 mpx, so i dont understand why 5888x3312 is returend by getSupportedPictureSizes() and i dont know how i must ignore non real values like that value.

这是无法正常运行的代码:

This is the code that does not work properly:

DecimalFormat localDecimalFormat = new DecimalFormat("#.#", symbols);   
        String sizeInMegapixel=getString(R.string.not_available);
        if(cam!=null){          
            Camera.Parameters camParams=cam.getParameters();
            List<Size> list = cam.getParameters().getSupportedPictureSizes();
            Camera.Size size;
            Size maxSize=list.get(0);
            int aux;
            int maxAux=0;           

            for (int i=0;i<list.size();i++){
                size=list.get(i);
                aux = size.width*size.height;
                if (aux>maxAux){
                    maxAux=aux;
                    maxSize=size;
                }
            }
            sizeInMegapixel=localDecimalFormat.format((maxSize.width*maxSize.height)/1000000.0D);
        }

推荐答案

Camera camera = Camera.open();
Parameters paramOfCamera = camera.getParameters();
android.hardware.Camera.Size sizeOfImage = paramOfCamera.getPictureSize();
int width = sizeOfImage .width ;
int height = sizeOfImage .height ;

double pixelOfCamera = (width*height)/1024000 ;

已更新

List<Size> sizes = paramOfCamera .getSupportedPictureSizes();
Size mSize = null;
for (Size size : sizes) {
        System.out.println("Size =="+size.width+"==Height=="+size.height);
        break;
}

您将获得所有受支持的尺寸,但第一个索引将提供最大图片尺寸.

You will get all supported size but first index will give maximum picture size.

这篇关于如何获得设备的真实Camera max Megapixels?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:44