Android development-specifies the image size when taking photos of the camera class,

Source: Internet
Author: User

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.

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.