Android calls the system camera's API interface in the Android.hardware package. The class of the package is mainly used in the camera class. The class contains several inner classes: Camera.parameters, Camera.camerainfo, Camera.picturecallback.
Camera.parameters is obtained by camera.parameters Parameters = Mcamera.getparameters (), mainly used to set the camera's parameters, including the format of the picture, whether to turn on the flash, etc.
Camera.camerainfo is via camerainfo info = new Camerainfo (); Camera.getcamerainfo (0, info), mainly used to obtain the camera's parameters, including the direction of the.
Camera.picturecallback is directly new Camera.picturecallback () and then implements the callback method inside, public void Onpicturetaken (byte[] data, Camera camera) to convert byte[] to bitmap.
The camera is called first int mcameraid = Camera.getnumberofcameras ()-1, Camera.open (Mcameraid). Adjust the orientation of the camera according to Camerainfo. Then click on take photo and call set Camera.parameters. Mcamera.takepicture (null, NULL, picturecallback), and finally gets the picture in Camera.picturecallback.
The class used to display the image in the Android.view package, Surfaceview, Surfaceholder, Surfaceholder.callback, is also required when invoking the system camera.
Msurfaceviewpicture = new Surfaceview (context), called after opening the camera
Msurfaceholder = Msurfaceviewpicture.getholder ();
Msurfaceholder.addcallback (Mcallback);
Set type
Msurfaceholder.settype (surfaceholder.surface_type_push_buffers);
Mpictureview.addview (msurfaceviewpicture);//mpictureview is framelayout used to display graphics.
Private Callback Mcallback = new Callback () {
@Override
public void surfacedestroyed (Surfaceholder holder) {
}
@Override
public void surfacecreated (Surfaceholder holder) {
try {
Mcamera.setpreviewdisplay (Msurfaceholder);
} catch (IOException e) {
LOGUTILS.E (TAG, "" +e.getmessage ());
if (Mcamera! = null) {
Mcamera.release ();
Mcamera = null;
}
}
}
@Override
public void surfacechanged (surfaceholder holder, int format, int width,
int height) {
if (Mcamera! = null) {
Camera.parameters Parameters = Mcamera.getparameters ();
Parameters.setpictureformat (Pixelformat.jpeg);
Mcamera.setparameters (parameters);
Mcamera.startpreview ();
}
}
};
Camera Photography in Android