> For the complete documentation index, see [llms.txt](https://handtracking.lightbuzz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://handtracking.lightbuzz.com/ui-reference/streamsource/webcamsource.md).

# WebcamSource

```csharp
public class WebcamSource : StreamSource
```

Inherits [StreamSource](/ui-reference/streamsource.md) class.

### Constructors

| Name           | Description                        |
| -------------- | ---------------------------------- |
| WebcamSource() | Creates a new WebcamSource object. |

### Properties

| Name          | Type                                                                                     | Description                                                                                             |
| ------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| WebcamIndex   | int                                                                                      | Read-Only. The webcam device index.                                                                     |
| WebcamTexture | [UnityEngine.WebCamTexture](https://docs.unity3d.com/ScriptReference/WebCamTexture.html) | Read-Only. The WebcamTexture onto which the live video input is rendered.                               |
| Timestamp     | DateTime                                                                                 | Read-Only. Overriden. The frame timestamp.                                                              |
| IsOpen        | bool                                                                                     | Read-Only. If the camera is currently playing and its Width and Height are greater than 16 pixels each. |
| IsPlaying     | bool                                                                                     | Read-Only. If the camera is currently playing.                                                          |
| Width         | int                                                                                      | Read-Only. Overriden. The width of the WebcamTexture in pixels.                                         |
| Height        | int                                                                                      | Read-Only. Overriden. The height of the WebcamTexture in pixels.                                        |
| Rotation      | int                                                                                      | Read-Only. Overriden. The rotation of the camera.                                                       |
| Pixels        | [UnityEngine.Color32](https://docs.unity3d.com/ScriptReference/Color32.html)\[]          | Read-Only. Overriden. The pixel color data for a mipmap level as Color32 structs.                       |
| Pointer       | IntPtr                                                                                   | Read-Only. Overriden. A native pointer to the WebcamTexture resource.                                   |

### Methods

| Name              | Return Type | Description                                                                  |
| ----------------- | ----------- | ---------------------------------------------------------------------------- |
| Open              | void        | Starts the camera if the app is granted access.                              |
| Close             | void        | Closes the camera.                                                           |
| Pause             | void        | Pauses the camera.                                                           |
| SwitchCamera(int) | void        | Closes the open camera and opens the camera with the specified device index. |

### Example

The example shows how to manage webcam functionality with the `WebcamSource` class.

#### Create a WebcamSource

To create a `Webcam`Source, add a field for Unity to serialize.&#x20;

```csharp
[SerializeField] private WebcamSource _webcam;
```

#### Open webcam

Open the webcam to get the live feed.

```csharp
_webcam.Open();
```

#### Get camera feed

To get the camera feed,  first add an `ImageView` field for Unity to serialize. Then, if the webcam is open and has a new frame, draw the texture.

<pre class="language-csharp"><code class="lang-csharp"><strong>//Create an ImageView
</strong>[SerializeField] private ImageView _image;

// Check if the webcam is open.
if (_webcam.IsOpen)
{
    // Draw the texture for the specified camera.
    _image.Load(_webcam);
}
</code></pre>

#### Close webcam

Close the webcam to stop the live feed.

<pre class="language-csharp"><code class="lang-csharp"><strong>_webcam.Close();
</strong></code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://handtracking.lightbuzz.com/ui-reference/streamsource/webcamsource.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
