Stay organized with collections
Save and categorize content based on your preferences.
PreviewCallback
interface PreviewCallback
Callback interface used to deliver copies of preview frames as they are displayed.
Summary
Public methods |
abstract Unit |
Called as preview frames are displayed.
|
Public methods
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Camera.PreviewCallback\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nPreviewCallback\n===============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/hardware/Camera.PreviewCallback \"View this page in Java\") \n\n```\ninterface PreviewCallback\n```\n\n|----------------------------------------------|\n| [android.hardware.Camera.PreviewCallback](#) |\n\n*** ** * ** ***\n\n| **This interface was deprecated in API level 21.**\n|\n| We recommend using the new [android.hardware.camera2](/reference/kotlin/android/hardware/camera2/package-summary) API for new applications.\n\nCallback interface used to deliver copies of preview frames as they are displayed.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onPreviewFrame](#onPreviewFrame(kotlin.ByteArray,%20android.hardware.Camera))`(`data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`, `camera:` `[Camera](/reference/kotlin/android/hardware/Camera)!`)` Called as preview frames are displayed. |\n\nPublic methods\n--------------\n\n### onPreviewFrame\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onPreviewFrame(\n data: ByteArray!, \n camera: Camera!\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nCalled as preview frames are displayed. This callback is invoked on the event thread [open(int)](/reference/kotlin/android/hardware/Camera#open(kotlin.Int)) was called from.\n\nIf using the [android.graphics.ImageFormat#YV12](../graphics/ImageFormat.html#YV12:kotlin.Int) format, refer to the equations in [Camera.Parameters.setPreviewFormat](/reference/kotlin/android/hardware/Camera.Parameters#setPreviewFormat(kotlin.Int)) for the arrangement of the pixel data in the preview callback buffers.\n\n| Parameters ||\n|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!: the contents of the preview frame in the format defined by [android.graphics.ImageFormat](../graphics/ImageFormat.html#), which can be queried with [android.hardware.Camera.Parameters#getPreviewFormat()](/reference/kotlin/android/hardware/Camera.Parameters#getPreviewFormat()). If [android.hardware.Camera.Parameters#setPreviewFormat(int)](/reference/kotlin/android/hardware/Camera.Parameters#setPreviewFormat(kotlin.Int)) is never called, the default will be the YCbCr_420_SP (NV21) format. |\n| `camera` | [Camera](/reference/kotlin/android/hardware/Camera)!: the Camera service object. |"]]