Android camera details

Source: Internet
Author: User

1. Start camera
1. An activity starts the call process:
Oncreate () --> onstart () --> onresume ()
Oncreate ():
1. You can add the layout file and draw the interface.
2. Enable the thread, start the hardware camera, and call cameraholder. instance (). open () to get an android. hardwarecamera instance mcameradevice
Ensurecameradevice () --> cameraholder. instance (). open () --> mcameradevice. getparameters (); Ensure that the camera exists and open the camera.
Startpreview (); Start Preview
3. Create a surfaceholder for videopreview and register the callback function. When the length and width of videopreview change, call the surfacechanged () function.
Msurfaceview = (surfaceview) findviewbyid (R. Id. camera_preview );
Surfaceholder holder = msurfaceview. getholder ();
Holder. addcallback (this );
Holder. settype (surfaceholder. surface_type_push_buffers );
4. Whether misimagecaptureintent is the intent sent from the short message or contact editing interface to camera
Misimagecaptureintent = isimagecaptureintent (); when this function returns true, it indicates that the photo page is redirected from the short message or contact interface;
If it is set to false, camera is started normally from the desktop program. Note that the functional buttons on the right are changed in two cases.
Onstart ():
1. mswitcher. setswitch (switch_camera) sets the camera recording switch button to switch to the camera mode.
Onresume ()
Startpreview () Start previewing again
1. When you press the Home Key to exit the program, the stoppreview () function will be disabled. Therefore, when you enter the program again, the onresume () function will be executed. In this function, you should re-enable the preview function.
2. keepscreenonawhile () lights up the screen to prevent screen blackening.

2. photo and video switching
1. switcher inherits from imageview and can be directly laid out in the layout file.
2. When mswitch is set to true, the slider is displayed at the bottom of the page. When mswitch is set to false, the slider is displayed at the top of the page.
3. When you click or touch the camera recording switch button:
Motionevent. action_up --> trytosetswitch () --> mlistener. onswitchchanged (this, Onoff)
To implement this interface in camera. Java, call switchtovideomode () --> menuhelper. gotovideomode (this) --> startcameraactivity () and end the current program.

3. Update to album button
1. Call event:
Initializefirsttime is called during initialization
Called at initializesecondtime ()
Intent. action_media_scanner_finished, called at the end of the SD card Scan
2. mthumbcontroller. isurivalid (). If there is an image in the Image Library, the value is true. If there is no image in the Image Library, the value is false.
3. updatelastimage (): The display image updated to the album button.
4. mthumbcontroller. updatedisplayifneeded () --> If (muri = NULL) mbutton. setimagedrawable (null); when there is no image in the Image Library, no photo is shown here.

4. shutterbutton
1. Focus call Process
Press the shutterbutton button on the screen.
The listener thread in shutterbutton. Java calls callshutterbuttonfocus (). This function calls the onshutterbutton. onshutterbuttonlistener function onshutterbuttonfocus ().
Camera. Java implements the interface shutterbutton. onshutterbuttonlistener. Therefore, the onshutterbuttonfocus () function in camera. Java is called.
The subsequent execution process is -----> dofocus () ------> autofocus () ---> mcameradevice. autofocus ()
2. Photo call Process
Then shutterbutton. Java calls performclick (), which calls onshutterbuttonclick () in camera. java ()
The subsequent execution process is -----> dosnap () -----> imagepicture. onsnap () -----> imagecapture. Initiate () ----> imagecapture. Capture (). After this function is executed, the takepicture process is completed.
After takepicture is complete, surfacechanged () will be called to display the photo you just took on the screen.
The onpicturetaken () function in the callback interface jpegpicturecallback in camera. Java is then executed. This function first calls imagecapture. storeimage () to store JPEG image data in the memory.
3. Picture's thumbnail display process:
Imagecapture. storeimage () ---> imagecapture. setlastpicturethumb () ---> mthumbcontroller. setdata (Uri, lastpicturethumb );

5. layout File

1. attach_camera_control.xml. When you enter camera from the short message or contact interface, click "OK" and "cancel" in the "function" area on the right"

2. layout of functional buttons on the Right of camera_control.xml, camera and videocamera Main Interface

3. Camera. xml: preview the Scenic Area Layout on the left of the main camera interface

4. video_camera.xml: preview the Scenic Area Layout on the left of the videocamera Main Interface

5. on_screen_hint.xml: the output of SD card-related information. For example, the following message is displayed: "Please insert the SD card before using the camera ."

6. Camera SD card

1. broadcastreceiver mreceiver, receives the status change message from the SD card.

2. Intent. action_media_mounted mounting

Intent. action_media_unmounted is not mounted

Intent. action_media_checking this status will be called when the SD card is not inserted into the Insert Process

Intent. action_media_scanner_finished: scanning the SD card ends, that is, the SD card enters the usable status.

3. checkstorage ()-> calculatepicturesremaining ()-> menuhelper. calculatepicturesremaining () Calculate the remaining space of the SD card

4. The updatestoragehint () interface prompts text display.

Among them, menuhelper. no_storage_error contains the SD card status: media_checking, media_shared, etc. The SD card is removed.

State = environment. getexternalstoragestate () Get the SD card status

For example, state. Equals (environment. media_checking) indicates that the SD card is being prepared.

Mstoragehint = onscreenhint. maketext (this, nostoragetext); set the content to be displayed on the current interface

Mstoragehint. Show (); displays the SD card status text

7. the SD card of the camera is a little more troublesome than the camera

1. register the receive event in the onresume () function

Intentfilter =
New intentfilter (intent. action_media_mounted );
Intentfilter. addaction (intent. action_media_eject );
Intentfilter. addaction (intent. action_media_unmounted );
Intentfilter. addaction (intent. action_media_scanner_started );
Intentfilter. addaction (intent. action_media_scanner_finished );
Intentfilter. adddatascheme ("file ");
Mreceiver = new mybroadcastreceiver ();
Registerreceiver (mreceiver, intentfilter );
Mstoragestatus = getstoragestatus (true );

2. Class mybroadcastreceiver processes the received above registration events

For example

If (action. Equals (intent. action_media_eject )){
Updateandshowstoragehint (false );
Stopvideorecording ();
} When the SD card is pulled out

3. updateandshowstoragehint ()-> getstoragestatus ()

When remaining = no_storage_error, you can add processing statuses such as share and checking.

Return different values based on different statuses.

For example:

If (State. Equals (environment. media_checking )){
Return storage_status_prepare;
} Else if (State. Equals (environment. media_shared )){
Return storage_status_share;
} Else {
Return storage_status_none;
}

Of course, the filled event needs to be registered in Step 1.2 and called

4. showstoragehint ()

Process the required display information in the switch (mstoragestatus)

For example, add the following case statement to process the share status added above.

Case storage_status_share:
Errormessage = getstring (R. String. sdcard_busy_message );
Break;

5. mstoragehint = onscreenhint. maketext (this, errormessage); set the text content to be displayed.

6. mstoragehint. Show (); displayed on the current camera interface

8. Go to the right side of the page for preview.

1. In the oncreat () or XML file, we cannot find the layout corresponding to the setting item. Where is the setting item added?

Changeheadupdisplaystate () This function is used to add the entry to this layout.

2. Res/XML/camera_preferences.xml

The corresponding image and text value are located under the XML file.


This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/dany1202/archive/2011/01/26/6164450.aspx

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.