Android Camera Camera Camera

Source: Internet
Author: User
Tags execution thread

A. Camera start
1. An activity initiates the calling process:
OnCreate ()-->onstart ()-->onresume ()
OnCreate ():
1. You can add the required layout files, draw the interface.
2. Open the thread, start the hardware camera, call Cameraholder.instance (). Open () to get a Android.hardwarecamera instance Mcameradevice

Ensurecameradevice ()-->cameraholder.instance (). Open ()-->mcameradevice.getparameters (); Make sure the camera is present and open the camera.

Startpreview (); Start View preview
3. Create Videopreview Surfaceholder, while registering the callback function, calling the surfacechanged () function when the Videopreview's long width changes

Msurfaceview = (Surfaceview) Findviewbyid (R.id.camera_preview);

Surfaceholder holder = Msurfaceview.getholder ();

Holder.addcallback (this);

Holder.settype (surfaceholder.surface_type_push_buffers);
4.mIsImageCaptureIntent is the intent sent from the SMS or contact editor interface to camera

Misimagecaptureintent = Isimagecaptureintent (); When the function returns True, it represents a jump from the SMS or contact interface to the camera interface;

False indicates that the camera is started normally from the desktop program, and that the right Interface function button area required for two different situations is changed.
OnStart ():
1.mswitcher.setswitch (Switch_camera) Set the camera video toggle button to switch to camera mode.
Onresume ()
Startpreview () re-start preview
1. When you press the home key to exit the program, you will lose the Stoppreview (), so when you enter again, you will perform the Onresume () function, in this function, the preview function should be turned back on.
2.keepScreenOnAwhile () Light the screen to prevent the screen from getting dark.

2. Camera video Switching function
1.Switcher inherits from ImageView, layout directly in Layout file
2.mSwitch is true, the slider is below, showing the camera interface, and when Mswitch is false, the slider is above and the video interface is displayed.
3. When clicking or touching the photo video toggle button:

Motionevent.action_up-->trytosetswitch ()-->mlistener.onswitchchanged (this, onoff)

Implement the interface in Camera.java, call Switchtovideomode ()-->menuhelper.gotovideomode (This)-->startcameraactivity (), and ends the current program.

3.updateThumbnailButton () Update function button go to album button
1. Invoke Event:

Called when Initializefirsttime is initialized

Called when Initializesecondtime ()

intent.action_media_scanner_finished, scan SD card at end of call
2.mthumbcontroller.isurivalid (), the value is true when there is a picture in the gallery, false when there is no picture in the gallery.
3.updateLastImage () update the display picture on the album button.
4.mthumbcontroller.updatedisplayifneeded ()-->if (MUri = = null) mbutton.setimagedrawable (null); no photos appear here when the gallery has no photos.

4.shutterButton Photo button
1. Focus Call Process
Press the Shutterbutton button on the screen.
The listener thread in the Shutterbutton.java calls Callshutterbuttonfocus (), which invokes the interface Shutterbutton.onshutterbuttonlistener function Onshutterbuttonfocus ().
Camera.java implements the interface Shutterbutton.onshutterbuttonlistener. Therefore, the function Onshutterbuttonfocus () in Camera.java is called.
The following execution process is-----> dofocus ()------>autofocus ()--->mcameradevice.autofocus ()
2. Photo Call Process
Then Shutterbutton.java calls PerformClick (), which calls the Onshutterbuttonclick in Camera.java ()
The following execution process is----->dosnap ()----->imagepicture.onsnap ()----->imagecapture.initiate ()----> Imagecapture.capture () After this function is finished, the takepicture process completes
When the takepicture is complete, surfacechanged () will be called to display the photos just taken on the screen.
The function Onpicturetaken () in the callback interface Jpegpicturecallback in Camera.java is then executed. This function first calls Imagecapture.storeimage () to store the JPEG image data in memory.
3.picture thumbnail Display process:
Imagecapture.storeimage ()--->imagecapture.setlastpicturethumb ()---> Mthumbcontroller.setdata (URI, LASTPICTURETHUMB);

5. layout file

1.attach_camera_control.xml, when entering camera from short message or contact interface, "OK" "Pat" and "Cancel" of the Right Function button area

Layout of the functional button area on the right side of the 2.camera_control.xml,camera and Videocamera main interface

3.camera.xml,camera main screen left preview of the layout of the scenic spot

4.video_camera.xml,videocamera main screen left preview of the layout of the scenic spot

5.ON_SCREEN_HINT.XML,SD Card related information output, such as at the bottom of the screen prompts "before using the camera, please insert the SD card." ”

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.