# WebcamSource

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

Inherits [StreamSource](https://handtracking.lightbuzz.com/ui-reference/streamsource) 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>
