1. Summary
First, you must briefly describe the relationship between surface and surfaceholder. callback.
Surface isAn important element of Android, used for drawing Android images. WhileSurfaceview is an inherited class of view. Each surfaceview encapsulates a surface. By calling surfaceholder, you can call surfaceview to control the image size and size. Surfaceholder is obtained through surfaceview. getholder. After creating a surfaceholder object, use surfaceholder. Callback () to call surfaceholder back and forth to control surfaceview.
It is a bit difficult to express in words, so the following section will be givenCodeFor understanding.
Surfaceholder holder = (surfaceview) findviewbyid (R. Id.Camerapreview). Getholder ();
Holder. addcallback (This);
Holder. Settype (surfaceholder.Surface_type_push_buffers);
In this way, you can useCallback() PairSurfaceview.
IICallback() Method Introduction
Callback() Includes three functions:
①Surfacecreated(SurfaceholderHolder)
This function is called immediately after surface is created for the first time.ProgramYou can perform initialization related to the drawing interface in this function. Generally, the interface is drawn in another thread, so do not draw the surface in this function.
Parameters
HolderTheSurfaceholder
② Surfacechanged(Surfaceholder holder, int format, int width, int height)
This function is called when the surface state (size and format) changes. After surfacecreated is called, the function is called at least once.
Parameters
Holder updateSurfaceSurfaceholder
New format
New width
HeightNew Height
③ Surfacedestroyed()
This function is called before the surface is destroyed. After the surface function is called, it cannot continue to use the surface function. Generally, this function cleans up the resources used.
Parameters
HolderTheSurfaceholder