(Android hardware Application Practice) camera photography implementation and summary

Source: Internet
Author: User

Two risks should be taken into consideration before camera photography can be used.

[1] Not every android machine can use your application

Main reasons:

The camera takes pictures. The app calls the android system API, the system API, and the underlying driver. The app calls the underlying driver hardware.

Generally, android mobile phones have a vendor-defined write driver to implement the operating system, and some customized small manufacturers' android system API implementations are not complete, or are not supported. As a result, an exception occurs when your application is installed.

[2] The response time varies depending on different models and brand machines.

Main reasons: Currently, the performance of the android mobile phone is still limited. The response time of the mobile phone hardware is not the same for different configurations. Example: Call the lens, the initialization time of the lens, the time when the camera responds to the camera instruction, etc.

 

Frontier:The practical application of this Article is timed continuous photo taking, and there is no flash or sound during the photo taking process. The following is a summary of the camera calling during the application implementation process.

 

1Step 1Initialize Camera

Initialization Process

Get a Camera instance

 

 camera =Camera.open();

 

Set the camera parameters (no flashlight and the camera angle turns 90 degrees). Note: The default camera is a horizontal camera)

 

Camera.Parameters parameters=camera.getParameters();
parameters.setFlashMode("off");
parameters.set("rotation",90);
camera.setParameters(parameters);

Enable Preview (you must call this function before executing the camera command)

 

 camera.startPreview();

 

2Set the camera instruction and callFeedback events to get and store photos

Set feedback events:

    PictureCallback pictureCallback=new PictureCallback(){
public void onPictureTaken(byte[] data,Camera camera)
{
FileOutputStream outSteam=null;

try{

SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
String times=format.format((new Date()));

outSteam=new FileOutputStream("/sdcard/MyImages/"+times+".jpg");
outSteam.write(data);
outSteam.close();

}
catch(FileNotFoundException e)
{
Log.d("Camera", "row");

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

};
};

 

Execute the photo instruction

 

3After taking the photo, release the camera.

camera.takePicture(null, null, pictureCallback);

4Configure permissions:

Set camera permissions in the AndroidManifest. xml file

<Uses-permission android: name = "android. permission. CAMERA"/>

 

Note: The current application has been released:

Http://www.appchina.com/soft_detail_180936_0_10.html

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.