android.hardware.Camera.PreviewCallback
官方介绍:Link
Class Overview
Callback interface used to deliver copies of preview frames as they are displayed.
Public Methods
public abstract void onPreviewFrame (byte[] data, Camera camera)
Called as preview frames are displayed. This callback is invoked on the event thread open(int)
was called from.
If using the YV12
format, refer to the equations in setPreviewFormat(int)
for the arrangement of the pixel data in the preview callback buffers.
Parameters
data | the contents of the preview frame in the format defined by ImageFormat , which can be queried with getPreviewFormat() . If setPreviewFormat(int) is never called, the default will be the YCbCr_420_SP (NV21) format. |
---|---|
camera | the Camera service object. |
如果 setPreviewCallback(Camera.PreviewCallback)
, setOneShotPreviewCallback(Camera.PreviewCallback)
, 或者 setPreviewCallbackWithBuffer(Camera.PreviewCallback)
被调用, 当预览数据可得到时,onPreviewFrame(byte[], Camera)
也会被调用。
-
public final void setPreviewCallback (Camera.PreviewCallback cb)
Installs a callback to be invoked for every preview frame in addition to displaying them on the screen. The callback will be repeatedly called for as long as preview is active. This method can be called at any time, even while preview is live. Any other preview callbacks are overridden.
Parameters
cb a callback object that receives a copy of each preview frame, or null to stop receiving callbacks. -
public final void setOneShotPreviewCallback (Camera.PreviewCallback cb)
Installs a callback to be invoked for the next preview frame in addition to displaying it on the screen. After one invocation, the callback is cleared. This method can be called any time, even when preview is live. Any other preview callbacks are overridden.
Parameters
cb a callback object that receives a copy of the next preview frame, or null to stop receiving callbacks -
public final void setPreviewCallbackWithBuffer (Camera.PreviewCallback cb)
Installs a callback to be invoked for every preview frame, using buffers supplied with
addCallbackBuffer(byte[])
, in addition to displaying them on the screen. The callback will be repeatedly called for as long as preview is active and buffers are available. Any other preview callbacks are overridden.The purpose of this method is to improve preview efficiency and frame rate by allowing preview frame memory reuse. You must call
addCallbackBuffer(byte[])
at some point -- before or after calling this method -- or no callbacks will received.The buffer queue will be cleared if this method is called with a null callback,setPreviewCallback(Camera.PreviewCallback) is called, or is called., or setOneShotPreviewCallback(Camera.PreviewCallback) is called.
Parameters
cb a callback object that receives a copy of the preview frame, or null to stop receiving callbacks and clear the buffer queue.