Camera-----------Essential features of the Android system

Source: Internet
Author: User

One in Android, the ACTION that corresponds to the photo is Android.provider.MediaStore.ACTION_IMAGE_CAPTURE. The activity used for taking pictures needs to return the photo image data,

The ACTION that corresponds to the camera is Android.provider.MediaStore.ACTION_VIDEO_CAPTURE

Therefore, you need to use Startactivityforresult () to start the Activity. The code is as follows:

Intent Intent = new Intent (mediastore.action_image_capture);

Startactivityforresult (intent,1);

The event method that intercepts the image data returned by the Activity is Onactivityresult, with the following code:

protected void Onactivityresult (int requestcode, int resultcode, Intent data) {

if (Requestcode = = 1) {

if (ResultCode = = ACTIVITY.RESULT_OK) {

Bitmap Bitmap = (Bitmap) Data.getextras (). Get ("data"); Photo Activity The key to save the image data is data, and the returned type is the Bitmap object

Imageview.setimagebitmap (bitmap); Displaying taken photos in the ImageView component

}

}

Super.onactivityresult (Requestcode, ResultCode, data);

}

System Photo function specific code see Ch14_systemcamera Engineering

Note: It is often difficult to take photos with a system, but you can generate photos with smaller resolutions. The Insertimage method allows you to generate a separate resolution in both the/sdcard/dcim/.thumbnails and/sdcard/dcim/camera directories. The rate is x 50 and 208 x 312 image, the code is as follows:

MediaStore.Images.Media.insertImage (Getcontentresolver (), camerabitmap,null,null);

Where Camerabitmap is the bitmap object returned by the photo Activity

Two implementation of user-defined photo Activity

The core class of the photo is Android.hardware.Camera, the camera object can be obtained through the static open of the camera class, and the camera class is started by the Startpreview method, and finally through the camera The Takepicture method of the class ends the photo and processes the photo data in the corresponding event

The steps are as follows:

1 specifies the container that is used to display the image of the photographic process, usually the Surfaceholder object.

2 in the photo process involves a number of state changes: These states include the beginning of the photo (corresponding to the Surfacecreated event method), picture state changes (corresponding to the Surfacechanged event method); End the photo (corresponding to the Surfacedestroyed event method). These 3 methods are defined in the Surfaceholder.callback interface, so the Surfaceholder.callback object needs to be specified using the Addcallback method of the Surfaceholder interface in order to implement these 3 methods

3 You need to process photo data after you have taken the picture. The work to process this data needs to be done in the Onpicturetaken method of the Pictruecallback interface. The Onpicturetaken method is called when the camera class's Takepicture method is called.

4 If autofocus is required, the AutoFocus method of the camera class needs to be called. The method requires a parameter value of type Autofocuscallback. Autofocuscallback is an interface in which a Onautofocus method is defined, which is called when the camera is focusing or focusing successfully.

For specific code, see Ch14_camera Engineering

Special Note: The user-defined camera feature must declare the permission <uses-permission android:name= "Android.permission.CAMERA"/> , but does not need to be declared when invoking the system-provided camera function !

http://blog.csdn.net/aduovip/article/details/6776765

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.