Camera Photography in Android

Source: Internet
Author: User

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

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.