An analysis of "Android" Camera usage

Source: Internet
Author: User


Brief analysis of the simple use of camera

As a result of the recent work on the use of Android.hardware.Camera this class, so simple to learn some basic usage.
First of all: Camera This class is not recommended after API21, the official provides a new class called: Camera2, which contains a new callback mechanism, interested friends can study carefully.
Camera Official API Guide: No wall and too lazy to open the local doc friend please poke:
Http://www.android-doc.com/guide/topics/media/camera.html

It describes the steps for taking pictures using camera:
1. Get an instance of the camera from open (int cameraid), and after Android2.3 you can pass in the corresponding Cameraid value to turn on the selected camera. Note: You need to call the Getnumberofcameras () method before using to get the number of cameras currently on the device to ensure that the device has multiple cameras available;

2. If required, you can call GetParameters () to get the current (default) settings, and define the Camera.parameters object, call Setparameters (camera.parameters) To configure the camera. such as Setwhitebalance (string), Setfocusmode (string value), etc., followed by Setparameters (camera.parameters) to ensure a successful setup;

3. Call Setdisplayorientation (int) To rotate the screen, because in portrait mode, the image captured by the camera is rotated 90 degrees counterclockwise. 注意: This method only affects the screen display (that is, the UI), does not affect the camera acquisition of the original frame, so if using Onpreviewframe (byte[] data, camera) This method to get the original frame to do rotate friend, Please do not waste any more time on this kind of official API.

4. The fully initialized Surfaceholder is passed into Setpreviewdisplay (Surfaceholder), and without surface, the camera does not turn on preview;

5. Call Startpreview () to update the surface of preview, you must start preview before taking the photo;

6. Next, call Takepicture (Camera.shuttercallback, Camera.picturecallback, Camera.picturecallback, Camera.PictureCallback ) method is used to photograph, callback will provide image data;

7. After taking the photo, preview display will stop, and if necessary, use Startpreview () again to take the more photos;

8. Call Stoppreview () to stop the update of the preview surface;

9. Call the release () method to release control of the camera, otherwise it will cause the camera's application (including the application) to crash when the camera is opened. And generally, the app should do the release () immediately after OnPause ().

关于Camera的几个注意事项:

Let's talk about the pit I stepped on:
-about the orientation of the camera acquisition of the original frame: if you need to use the original frame of the friend should know that Android (here is said API21 below) the camera acquisition direction is always landscape mode. So the official offer of several rotational methods such as: setdisplayorientation (int), setcameradisplayorientation (), Changeorientationlistener (), etc. Have no effect on the data in the Onpreviewframe. )

Official note: This does not affect the order of a byte array passed in onPreviewFrame(byte[], Camera) , JPEG pictures, or recorded videos. This method isn't allowed to be called during preview.


An analysis of "Android" Camera usage

Related Article

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.