Java Online Photo code
The popularity of digital cameras (especially on phone phones) has led to their falling prices as much as their size has shrunk.
It is now becoming harder to find, even without the camera's phone, and robotic devices are no exception. To access the camera
Hardware, you need to add the list of licensed applications to your camera, as follows:
<uses-permission android:name= "Android.permission.CAMERA"/>
This grants access to the camera service. The camera class can adjust camera settings, take photos, camera and process streaming media previews. To
Access the camera service, using the open method of the camera's static class. When your app is behind the camera, remember to call
The code fragment of the simple usage pattern released after the abort shows you the service:
Camera Camera = Camera.open ();
[ ... Do things with the camera ...]
Camera.release ();
Control camera settings
The current camera settings can be used as camera.parameters objects. Call for camera GetParameters method to visit
Ask the current argument. You can modify the settings using the parameter * method that is set on the return. To apply your changes,
Setparameters, as the revised value of the inheritance is as follows:
Camera.parameters Parameters = Camera.getparameters ();
Parameters.setpictureformat (Pixelformat.jpeg);
Camera.setparameters (parameters);
The camera's parameters can be used to specify the picture and preview size, image format, and preview frame rate.
Use Camera Preview
Streaming video into the camera means you can merge into the live video. The most exciting early robot applications
Some of this functionality is used as a practical basis for enrichment. The camera can display previews in real time to a surface, such as the following code
The fragment shows:
Camera.setpreviewdisplay (Mysurface);
Camera.startpreview ();
[ ... ]
Camera.stoppreview ();
You will learn more about the surface of the next chapter, though the robot includes a preview with a surfaceview display real time camera well
The example. This example can be shown in graphics/Camerapreview in the SDK API demo project.
You can also specify that a previewcallback be fired each preview box, allowing you to manipulate or display each individual frame preview
。 Call the object's camera Setpreviewcallback method, covering the new Previewcallback
The execution of the Onpreviewframe method pass is as follows:
Camera.setpreviewcallback (New Previewcallback () {
public void Onpreviewframe (byte[] _data, Camera _camera) {
TODO do something with the preview image.
}
});
Over call a camera object takepicture picture, in Shuttercallback and Raw and JPEG
Picturecallback implements the encoded image. Each picture callback will receive an array of bytes to represent the appropriate lattice
-style image, while the shutter callback triggers the shutter to close immediately after
private void Takepicture () {
Camera.takepicture (Shuttercallback, Rawcallback, Jpegcallback);
}
Shuttercallback shuttercallback = new Shuttercallback () {
public void Onshutter () {
TODO do something the shutter closes.
}
};
Picturecallback rawcallback = new Picturecallback () {
public void Onpicturetaken (byte[] _data, Camera _camera) {
TODO do something with the image RAW data.
}
};
Picturecallback jpegcallback = new Picturecallback () {
public void Onpicturetaken (byte[] _data, Camera _camera) {
TODO do something with the image JPEG data.
}
};