简体   繁体   中英

How to get real Camera max Megapixels of a device?

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.

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...)

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

so i dont understand why 5888x3312 is returend by getSupportedPictureSizes()

Because that is what the manufacturer thinks is the largest supported picture size. Try taking a picture at that size -- if it fails, then there is a bug in this device. If it succeeds, then perhaps you are wrong about the camera resolution.

i dont know how i must ignore non real values like that value

You don't, other than through testing. Device manufacturers return curious values from getSupportedPictureSizes() all the time.

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 ;

Updated

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.

if you've got the camera object, try

android.hardware.Camera.Parameters parameters = camera.getParameters();
android.hardware.Camera.Size size = parameters.getPictureSize();


int height = size.height;
int width = size.width;

As the megapixels in the pickup device in your camera increase so does the possible maximum size image you can produce. This means that a 5 megapixel camera is capable of capturing a larger image than a 3 megapixel camera.

Example: 1936 x 1552 / 1024000 = 3 Mega Pixels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM