# Capture Photo from Camera

## Goal

Use the device camera to capture a photo and display it in your game UI.

## Actions Required

| Action                              | Purpose                                         |
| ----------------------------------- | ----------------------------------------------- |
| MediaServicesGetCameraAccessStatus  | Read current camera permission status           |
| MediaServicesCaptureContent         | Capture a photo (fires success/failure events)  |
| MediaServicesGetContentTexture      | Convert captured content (index 0) to Texture2D |
| MediaServicesGetCaptureContentError | Read cached error after failure (optional)      |

## Variables Needed

* cameraStatus (Enum: CameraAccessStatus)
* capturedTexture (Texture2D)
* errorCode (Int) (optional)
* errorDescription (String) (optional)

## Implementation Steps

### 1. State: CheckCameraPermission

**Action:** MediaServicesGetCameraAccessStatus

* **Outputs:**
  * status → cameraStatus
* **Next:** Use an Enum Switch/Compare on `cameraStatus`:
  * `Authorized` / `NotDetermined` → CapturePhoto
  * `Denied` / `Restricted` → ShowPermissionError

### 2. State: CapturePhoto

**Action:** MediaServicesCaptureContent

* **Inputs:**
  * captureType: Image
  * customTitle: "Take Photo" (optional)
* **Events:**
  * successEvent → ConvertToTexture
  * failureEvent → GetCaptureError

**Note:** This opens the native camera UI and waits for the callback.

### 3. State: ConvertToTexture

**Action:** MediaServicesGetContentTexture

* **Inputs:**
  * contentIndex: 0 (first/only captured image)
* **Outputs:**
  * texture → capturedTexture
* **Next:** This action finishes when conversion completes. Use the state’s `FINISHED` transition → DisplayPhoto.

### 4. State: DisplayPhoto

Assign capturedTexture to UI Image component:

```
uiImage.texture = capturedTexture
```

### 5. (Optional) GetCaptureError

On `failureEvent`, call `MediaServicesGetCaptureContentError` to read `errorCode` + `errorDescription`.

## Capture Flow

```
CheckCameraPermission
    ├─ status = Authorized/NotDetermined → CapturePhoto
    └─ status = Denied/Restricted → ShowPermissionError

CapturePhoto
    └─ Success → ConvertToTexture
        └─ DisplayPhoto
```

## Common Issues

* **Permission Denied**: Guide user to Settings to enable camera access
* **Camera Unavailable**: Check if device has a camera (some tablets don't)
* **Texture is Null**: Ensure ConvertToTexture completes before accessing texture
* **Memory Issues**: Large photos can use significant memory; consider resizing

## Platform Differences

**iOS:**

* Requires "Privacy - Camera Usage Description" in Info.plist
* Permission prompt shown automatically on first use

**Android:**

* Requires CAMERA permission in AndroidManifest.xml
* Permission request may show before camera opens

## Performance Tips

* **Texture Size**: Captured photos can be large (4K+); resize if only displaying thumbnails
* **Memory Management**: Dispose of textures when no longer needed
* **Preview vs Final**: Consider showing preview before converting to final texture


---

# Agent Instructions: 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:

```
GET https://assetstore.essentialkit.voxelbusters.com/features/media-services/playmaker/use-cases/use-case-1-capture-photo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
