Ref :
http://blog.rhesoft.com/2015/04/02/tutorial-how-to-use-camera-with-android-and-android-studio/
II - Creating a new project
Open your Android Studio and create a new blank activity application.
The first step is to add the android permissions and required features.
Add these lines to your AndroidManifest.xml:
Inside your style.xml, just edit the line to remove the ActionBar, if you prefer(this is removed just to have a full-screen camera):
Create this basic activity_main.xml:
Here we have a simple FrameLayout.
The camera_view will display the camera data, that we’ll use later with OpenGL and some algorithms to process it.
And the ImageButton will be used to close the application.
III - Camera code
The first step is to create a SurfaceView. It’ll receive camera data and display it inside the FrameLayout.
Create a new file, CameraView.java in the same folder that your MainActivity.java is.
First, just extend the SurfaceView and implements the SurfaceHolder.Callback.
You’ll have something like this code:
Add these two private variables:
And then just update your CameraView constructor with:
Now, override these methods, I commented everything to help you:
III - Camera Activity
Now, inside you MainActivity.java, add these variables:
沒有留言:
張貼留言