From abe2decb9e7a6a60039c4dd367ef76bf13c2c22c Mon Sep 17 00:00:00 2001
From: Sparky Rhode
-private void openCameraPerIdAndSetPreview() {
- if (! safeCameraOpen(mCameraId)) {
- mCameraId = getFirstRearCameraID();
- safeCameraOpen(mCameraId);
- }
-
- mPreview.setCamera(mCamera);
-}
-
-
-Since API level 9, the camera framework supports multiple cameras. If you use the -legacy API and call {@link android.hardware.Camera#open open()} without an -argument, you get the first rear-facing camera. Dealing with multiple cameras -is an advanced topic and beyond the scope of this lesson. If you are really -interested, check out the implementation of {@code getFirstRearCameraID()} in -the sample app (downloadable at the top).
-Calling {@link android.hardware.Camera#open Camera.open()} throws an exception if the camera is already in use by another application, so we wrap it in a {@code try} block.
@@ -78,7 +60,7 @@ private boolean safeCameraOpen(int id) { try { releaseCameraAndPreview(); - mCamera = Camera.open(mCameraId); + mCamera = Camera.open(id); qOpened = (mCamera != null); } catch (Exception e) { Log.e(getString(R.string.app_name), "failed to open Camera"); @@ -97,6 +79,10 @@ private void releaseCameraAndPreview() { } +Since API level 9, the camera framework supports multiple cameras. If you use the +legacy API and call {@link android.hardware.Camera#open open()} without an +argument, you get the first rear-facing camera.
+
class Preview extends ViewGroup implements SurfaceHolder.Callback {
-...
SurfaceView mSurfaceView;
SurfaceHolder mHolder;
-...
-
Preview(Context context) {
super(context);
@@ -137,14 +120,13 @@ class Preview extends ViewGroup implements SurfaceHolder.Callback {
The preview class must be passed to the {@link android.hardware.Camera} object before the live -image preview can be started, as seen in {@code setCamera()} method of the sample, -as shown in the next section.
+image preview can be started, as shown in the next section.A camera instance and its related preview must be created in a specific -order, with the camera object being first. In the sample application, the +order, with the camera object being first. In the snippet below, the process of initializing the camera is encapsulated so that {@link android.hardware.Camera#startPreview Camera.startPreview()} is called by the {@code setCamera()} method, whenever the user does something to change the @@ -183,9 +165,8 @@ public void setCamera(Camera camera) {
Camera settings change the way that the camera takes pictures, from the zoom -level to exposure compensation. This example doesn’t do a whole lot with camera -settings, but the APIs provide a wide array of options. The {@code surfaceChanged()} method in the -sample app demonstrates how to get and set camera parameters:
+level to exposure compensation. This example changes only the preview size; +see the source code of the Camera application for many more.
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
@@ -221,9 +202,7 @@ to API level 14, you must stop your preview before changing the orientation and
method to take a picture once the preview is started. You can create {@link
android.hardware.Camera.PictureCallback} and {@link
android.hardware.Camera.ShutterCallback} objects and pass them into {@link
-android.hardware.Camera#takePicture Camera.takePicture()}. Since the Android
-Camera application already does a great job capturing JPEG images, you should
-probably implement the raw-image callback.
+android.hardware.Camera#takePicture Camera.takePicture()}.
If you want to grab images continously, you can create a {@link
android.hardware.Camera.PreviewCallback} that implements {@link
@@ -236,8 +215,8 @@ takePicture()}.
Restart the Preview
After a picture is taken, you must to restart the preview before the user
-can take another picture. In the example, the restart is done by overloading
-the shutter button, as shown below.
+can take another picture. In this example, the restart is done by overloading
+the shutter button.
@Override
@@ -302,7 +281,7 @@ private void stopPreviewAndFreeCamera() {
}
-In the example application, this procedure is also part of the {@code
+
Earlier in the lesson, this procedure was also part of the {@code
setCamera()} method, so initializing a camera always begins with stopping the
preview.
diff --git a/docs/html/training/camera/index.jd b/docs/html/training/camera/index.jd
index 400f636..31adfe8 100644
--- a/docs/html/training/camera/index.jd
+++ b/docs/html/training/camera/index.jd
@@ -28,7 +28,7 @@ next.link=photobasics.html
Try it out
--
cgit v1.1