Android development and learning-Camera functions in Camera mode (2)-Camera function configuration

Source: Internet
Author: User

The simple project we implemented in the previous article, and now we continue to add features for this camera. First, in Camera, we can perform simple control over the Camera. When we need to configure more functions, we need to use the Parameters class under Camera. The Parameters class encapsulates most of the functions we need. Here we will explain them one by one:

1. The setPictureFormat () method is used to set the format of the camera photo. The parameter is a two-dimensional parameter located in the PixelFormat class. Here we select PixelFormat. JPEG.

2. The setSceneMode () method is used to set the camera scene type. The parameter is a camera-type parameter located in the Parameters class and starts with SCENE_MODE.

3. The setZoom () method is used to set the Camera focal length. The parameter is an integer parameter and the range of this parameter is 0 to Camera. getParameters (). getMaxZoom ().

4. The setPictureSize () method is used to set the camera image size. The parameter is an integer.

5. setWhiteBalance () is used to set the white balance of the camera image. The parameter is a quiet parameter, which is located in the Parameters class and starts with WHITE_BALANCE.

6. The setJpegQuality () method is used to set the quality of the camera photos. The parameter is an integer parameter and the value ranges from 1 to 100.

7. setFlashMode () is used to set the flashlight type. The parameter is a quiet parameter located in the Parameters class and starts with FLASH_MODE.

8. The setColorEffect () method is used to set the type of the photo color EFFECT. The parameter is a quiet parameter located in the Parameters class and starts with EFFECT.

Well, here we only study this basic method. You can understand other methods on your own. Next we will take the setZoom () method as an example to explain the camera configuration. To add the zoom function to our program, we can modify the layout code of the program here:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <RelativeLayout        android:layout_width="wrap_content"        android:layout_height="0dp"         android:layout_weight="0.8">        <FrameLayout            android:id="@+id/PreviewView"            android:layout_width="match_parent"            android:layout_height="match_parent">        </FrameLayout>        <SeekBar            android:id="@+id/ZoomBar"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:layout_alignParentLeft="true"            android:layout_alignParentRight="true" />    </RelativeLayout>    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="0.2"        android:background="@drawable/main_bg">        <Button            android:id="@+id/BtnCapture"            android:layout_width="60dp"            android:layout_height="60dp"            android:layout_centerHorizontal="true"            android:layout_centerVertical="true"            android:background="@drawable/camera"/>        <ImageView            android:id="@+id/ThumbsView"            android:layout_width="60dp"            android:layout_height="60dp"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_margin="15dp"            android:contentDescription="@string/Description" />    </RelativeLayout></LinearLayout>
Correspondingly, we modify our logic code and add the following code:

/** Focal length adjustment **/mZoomBar = (SeekBar) findViewById (R. id. zoomBar);/** set the maximum focal length adjustment **/mZoomBar. setMax (mCamera. getParameters (). getMaxZoom (); mZoomBar. setOnSeekBarChangeListener (new OnSeekBarChangeListener () {@ Overridepublic void onProgressChanged (SeekBar arg0, int arg1, boolean arg2) {setZoom (mZoomBar. getProgress () ;}@ Overridepublic void onStartTrackingTouch (SeekBar arg0) {}@ Overridepublic void onStopTrackingTouch (SeekBar arg0 ){}});
The setZoom () method is defined as follows:

/** Set the Camera focal length **/private void setZoom (int mValue) {Camera. parameters mParams = mCamera. getParameters (); mParams. setZoom (mValue); mCamera. setParameters (mParams );}
Let's take a look at the running effect.

 

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.