Android development-specifies the image size when taking photos of the camera class,
Android photo development
There are two main ways to implement the camera function in android development:
- Directly call the System camera API to take a photo. After the photo is taken, the image is saved in the album and the path of the photo is returned to obtain the image.
- Write SurfaceView on your own and call camera to take a photo. This method triggers a callback. The parameter contains an array of image bytes to obtain the image.
Problem
When you customize a camera, you need to specify the image size. However, different mobile phones will return different resolution photos by default. Therefore, you need to set parameters for camera. By setting setPictureSize, the Code is as follows:
// Obtain the Camera Parameter camera. Parameters parameters = Camera. getParameters (); parameters. setPictureSize (480,360 );
The result is on P8 and the task is stopped directly.
Solution:
Therefore, you cannot fix a specific resolution in camera. The method of the Camera. Parameters class getSupportedPictureSizes (). This method returns a List containing all supported dimensions. Based on the obtained value, calculate the size that best suits you.
List<Size> list = parameters.getSupportedPictureSizes(); Camera.Size size = list.get(0); parameters.setPictureSize(size.width, size.height); camera.setParameters(parameters);
Here is the first in the list, with the minimum resolution. If the maximum value is obtained, the test finds that the camera speed is too slow.
The collection returned by getSupportedPictureSizes () is sorted, but the ascending order is still descending, Which is returned by the mobile phone. Therefore, the first element cannot be blindly obtained during processing. You can also go to the intermediate value.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.