Android obtains camera pixels

Source: Internet
Author: User

Get the camera instance. You can use the static method camera = camera before 2.3. open (); If the mobile phone carries a front-and-rear camera, the Instance obtained by SDK before 2.3 is the back-mounted main camera, and the front camera cannot be obtained.

Obtain parameters = camera. getparameters (); There is a getsupportedpicturesizes () method in parameters to obtain all supported image pixels. Loop to obtain the maximum width and height (the maximum value is generally the first element of the list, so you can directly get (0 )).

Width * height is the pixel of the camera! For example, 500 million pixels!

For SDK 2.3 or above, you can use camera. getnumberofcameras () to obtain the number of cameras. (Some mobile phones have three cameras, one on the front and two on the rear, but the value here is still 2 ). Camera. Open (INT cameraid) gets an exponential camera instance.

    public int getCameraId(int type) {        int numberOfCameras = Camera.getNumberOfCameras();        CameraInfo cameraInfo = new CameraInfo();        for (int i = 0; i < numberOfCameras; i++) {            Camera.getCameraInfo(i, cameraInfo);            if (cameraInfo.facing == type) {                return i;            }        }        return 2;    }

Int type is public static final int camera_facing_back = 0; public static final int camera_facing_front = 1;

Retrieve the front camera or the rear camera and calculate the camera Pixel based on the above method! Note: Generally, the calculated value is smaller than the value marked on the Internet, and the manufacturer exaggerated its own product!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.