Android calls the camera to take photos

Now, the pixels of Android smart phones will provide the function of taking pictures. The pixels of most mobile phones' cameras are more than 10 million pixels, and some are even higher. Most of them will support optical zoom, exposure, shutter and so on.

The following demo example demonstrates the use of camera V2 to take photos. When the user presses the photo key, the application will focus automatically, and take photos when the focusing is successful.

layout/activity_ The main.xml interface layout code is as follows:

The interface of the above program provides a custom TextureView to display preview viewfinder, which is very simple. The code of the custom TextureView class is as follows:

The logic code of autofittextureview.java is as follows:

The received mainactivity.java program will use cameramanager to open cameradevice, create cameracapturesession through cameradevice, and then preview or take photos through cameracapturesession.

The logic code of mainactivity.java is as follows:

The code of serial number ① in the above program is used to open the system camera. The first parameter of opencamera() method represents the camera ID requested to open. The camera ID passed in here is "0", which means to open the rear camera of the device; If you need to open the device specified camera (such as the front camera), you can pass in the corresponding camera ID when calling the opencamera () method.

Note: since the program needs to use the camera of the mobile phone, it also needs to authorize the corresponding permissions in the list file androidmanifest.xml:

The screenshot of demo program running effect interface is as follows:

Demo program source code download address

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>