Analysis of two methods of Android programming to realize photographing function

This paper describes two methods of Android programming to realize the photographing function. Share with you for your reference, as follows:

The camera function of Android system has realized two methods for your reference:

1. Call the system camera to take photos

First, find the androidmanifest.xml file and add user permissions

Secondly, two controls (button and ImageView) are added to the main class java file to trigger button events and display pictures. They are purely personal hobbies

The key is here:

Is to open the system's own camera. The following is the data obtained by processing photos and saving the data

In this way, you can call the camera provided by the system, which is a very simple operation.

2. Write your own program to save photos

These definitions should be made in the photo pattern file lay.xml

Surfaceview is used for preview. Initialize a series of values in oncreat function:

First, initialize the function and parameter settings of the camera:

After successful initialization, you can take photos. The camera function is still implemented by calling the function of camera class

Just implement the JPEG callback callback function to decode and save. The first two parameters can be directly set to null, but the system will generally help you write them in automatically

After taking pictures, reset the camera, and then continue taking pictures

Comparison of two photographing methods

① Call the camera provided by the system. There are only several options for the format and size of the photo. The photo is relatively large. If your own program is implemented, you can adjust the size of the photo to any size, and the capacity of the picture can be adjusted

② Calling the system is simple, and the appearance is generally better than what you set

③ The operation of calling the system is simple, convenient and not easy to make mistakes. If you program yourself, you need to pay attention to it, which is easy to cause system errors and accidental termination

More readers interested in Android related content can view the special topics of this site: summary of Android photography and image processing skills, summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills , Android layout skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>