Stay organized with collections
Save and categorize content based on your preferences.
Camera.PreviewCallback
public
static
interface
Camera.PreviewCallback
android.hardware.Camera.PreviewCallback
|
This interface was deprecated
in API level 21.
We recommend using the new android.hardware.camera2
API for new
applications.
Callback interface used to deliver copies of preview frames as
they are displayed.
Summary
Public methods |
abstract
void
|
onPreviewFrame(byte[] data, Camera camera)
Called as preview frames are displayed.
|
Public methods
onPreviewFrame
public abstract void onPreviewFrame (byte[] data,
Camera camera)
Called as preview frames are displayed. This callback is invoked
on the event thread Camera.open(int)
was called from.
If using the ImageFormat.YV12
format,
refer to the equations in Camera.Parameters.setPreviewFormat
for the arrangement of the pixel data in the preview callback
buffers.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Camera.PreviewCallback\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nDeprecated in [API level\n21](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nCamera.PreviewCallback\n======================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/hardware/Camera.PreviewCallback \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nCamera.PreviewCallback\n`\n\n\n`\n\n\n`\n\n|-----------------------------------------|\n| android.hardware.Camera.PreviewCallback |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\n**This interface was deprecated\nin API level 21.** \n\nWe recommend using the new [android.hardware.camera2](/reference/android/hardware/camera2/package-summary) API for new\napplications.\n\nCallback interface used to deliver copies of preview frames as\nthey are displayed. \n**See also:**\n\n- [Camera.setPreviewCallback(Camera.PreviewCallback)](/reference/android/hardware/Camera#setPreviewCallback(android.hardware.Camera.PreviewCallback))\n- [Camera.setOneShotPreviewCallback(Camera.PreviewCallback)](/reference/android/hardware/Camera#setOneShotPreviewCallback(android.hardware.Camera.PreviewCallback))\n- [Camera.setPreviewCallbackWithBuffer(Camera.PreviewCallback)](/reference/android/hardware/Camera#setPreviewCallbackWithBuffer(android.hardware.Camera.PreviewCallback))\n- [Camera.startPreview()](/reference/android/hardware/Camera#startPreview())\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onPreviewFrame](/reference/android/hardware/Camera.PreviewCallback#onPreviewFrame(byte[],%20android.hardware.Camera))`(byte[] data, `[Camera](/reference/android/hardware/Camera)` camera) ` Called as preview frames are displayed. |\n\nPublic methods\n--------------\n\n### onPreviewFrame\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onPreviewFrame (byte[] data, \n Camera camera)\n```\n\nCalled as preview frames are displayed. This callback is invoked\non the event thread [Camera.open(int)](/reference/android/hardware/Camera#open(int)) was called from.\n\nIf using the [ImageFormat.YV12](/reference/android/graphics/ImageFormat#YV12) format,\nrefer to the equations in [Camera.Parameters.setPreviewFormat](/reference/android/hardware/Camera.Parameters#setPreviewFormat(int))\nfor the arrangement of the pixel data in the preview callback\nbuffers.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | `byte`: the contents of the preview frame in the format defined by [ImageFormat](/reference/android/graphics/ImageFormat), which can be queried with [Camera.Parameters.getPreviewFormat()](/reference/android/hardware/Camera.Parameters#getPreviewFormat()). If [Camera.Parameters.setPreviewFormat(int)](/reference/android/hardware/Camera.Parameters#setPreviewFormat(int)) is never called, the default will be the YCbCr_420_SP (NV21) format. \u003cbr /\u003e |\n| `camera` | `Camera`: the Camera service object. \u003cbr /\u003e |"]]