Game Development Reference
In-Depth Information
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
Log.d(TAG, "surfaceCreated Stop camera");
camera.stopPreview();
camera = null;
}
}
Tip The Camera API requires a surface view to display a video feed. This surface view can then be
assigned as the content view of the main activity, thus rendering the video feed in the application.
CameraSurface extends the Android base class SurfaceView ,. It provides a dedicated
drawing surface embedded inside of a view hierarchy. So, you can control the format of this
surface and, if you like, its size; SurfaceView takes care of placing the surface at the correct
location on the screen. The surface view also implements a SurfaceHolder.Callback . A
client may implement this interface to receive information about changes to the surface such
as surfaceCreated , surfaceChanged , and surfaceDestroyed .
surfaceCreated
surfaceCreated is called immediately after the surface is first created. It is commonly used
to initialize rendering code. Note that only one thread can ever draw into a surface, so you
should not draw into the surface here if your normal rendering will be in another thread. In
Listing 9-2, this function performs the following steps:
It creates a new Camera object to access the first back-facing camera
on the device. If the device does not have a back-facing camera, this
returns null.
1.
Next, it calls setPreviewDisplay to set the surface to be used for live
preview. Either a surface or surface texture is necessary for preview,
and preview is necessary to take pictures.
2.
 
 
Search WWH ::




Custom Search