# Virtual backgrounds

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

The Video SDK for iOS lets you replace a user's camera background with a virtual background. Enable it through `ZoomVideoSDKVirtualBackgroundHelper`. First determine whether the device supports it using `isSupportVirtualBackground`. If the device supports it, use the helper methods to add, get, set, and remove virtual backgrounds.

## Typical flow

To add a virtual background and apply it to your video:

1. Use `addVirtualBackgroundItem` to add a virtual background item.
2. Use `getVirtualBackgroundItemList` to get a list of available virtual background items.
3. Choose a virtual background item from the list and use `setVirtualBackgroundItem` to set the virtual background.

Use `removeVirtualBackgroundItem` to remove the virtual background or set the virtual background to None. Use `getSelectedVirtualBackgroundItem` to get the currently selected background.

## Example

This example checks for device support, adds a background from a `UIImage`, sets it as the active background, then reads back the current selection and the full list of items.

```swift
if let vbHelper = ZoomVideoSDK.shareInstance()?.getVirtualBackgroundHelper(), vbHelper.isSupportVirtualBackground() {
    // Add a background from a UIImage (for example, from your asset catalog).
    let newItem = vbHelper.addVirtualBackgroundItem(image: backgroundImage)

    // Set the new background as the active one.
    vbHelper.setVirtualBackgroundItem(imageItem: newItem)

    // Later, read or replace the current selection.
    let selected = vbHelper.getSelectedVirtualBackgroundItem()
    let allItems = vbHelper.getVirtualBackgroundItemList()
}
```

```objectivec
ZoomVideoSDKVirtualBackgroundHelper *vbHelper = [[ZoomVideoSDK shareInstance] getVirtualBackgroundHelper];

if ([vbHelper isSupportVirtualBackground]) {
    // Add a background from a UIImage (for example, from your asset catalog).
    ZoomVideoSDKVirtualBackgroundItem *newItem = [vbHelper addVirtualBackgroundItem:backgroundImage];

    // Set the new background as the active one.
    [vbHelper setVirtualBackgroundItem:newItem];

    // Later, read or replace the current selection.
    ZoomVideoSDKVirtualBackgroundItem *selected = [vbHelper getSelectedVirtualBackgroundItem];
    NSArray<ZoomVideoSDKVirtualBackgroundItem *> *allItems = [vbHelper getVirtualBackgroundItemList];
}
```

## Method reference

The full set of `ZoomVideoSDKVirtualBackgroundHelper` methods for adding, listing, setting, and removing virtual backgrounds.

```swift
// Check if virtual background is supported
func isSupportVirtualBackground() -> Bool

// Add virtual background item
func addVirtualBackgroundItem(image: UIImage?) -> ZoomVideoSDKVirtualBackgroundItem?

// Remove virtual background item
func removeVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem?) -> ZoomVideoSDKError

// Get virtual background item list
func getVirtualBackgroundItemList() -> [ZoomVideoSDKVirtualBackgroundItem]?

// Set virtual background item
func setVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem?) -> ZoomVideoSDKError

// Get selected virtual background
func getSelectedVirtualBackgroundItem() -> ZoomVideoSDKVirtualBackgroundItem?
```

```objectivec
// Check if virtual background is supported
- (BOOL) isSupportVirtualBackground

// Add virtual background item
- (ZoomVideoSDKVirtualBackgroundItem *_Nullable) addVirtualBackgroundItem:(UIImage *_Nullable)image

// Remove virtual background item
- (ZoomVideoSDKError) removeVirtualBackgroundItem:(ZoomVideoSDKVirtualBackgroundItem *_Nullable)imageItem

// Get virtual background item list
- (NSArray<ZoomVideoSDKVirtualBackgroundItem *> *_Nullable) getVirtualBackgroundItemList

// Set virtual background item
- (ZoomVideoSDKError) setVirtualBackgroundItem:(ZoomVideoSDKVirtualBackgroundItem *_Nullable)imageItem

// Get selected virtual background
- (ZoomVideoSDKVirtualBackgroundItem *_Nullable) getSelectedVirtualBackgroundItem
```
