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!