# Virtual Background (/en/realtime-media/broadcast-streaming/build/apply-effects-and-enhancements/virtual-background/ios)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Virtual Background enables users to blur their background, or replace it with a solid color or an image. This feature is applicable to use-cases such as online conferences, online classes, and live streaming. It helps protect personal privacy and reduces audience distraction.

      
  
      
    ## Understand the tech [#understand-the-tech-1]

    Virtual Background offers the following options:

    | Feature                                 | Example                                                                                                                                                                                                                                                                                                               |
    | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | Blurred background and image background | ![image](https://assets-docs.agora.io/images/extensions-marketplace/blurred-background.jpg)                                                                                                                                                                                                                           |
    | Video/Animated background               | <video src="https://assets-docs.agora.io/images/extensions-marketplace/virtual-background.mp4" poster="https://web-cdn.agora.io/docs-files/1654571689670" width="100%" height="auto">Your browser does not support the `video` element.</video>                                                                       |
    | Portrait-in-picture                     | ![portrait-in-picture](https://assets-docs.agora.io/images/extensions-marketplace/portrait-in-picture.jpg) Allows the presenter to use slides as the virtual background while superimposing their video. The effect is similar to a weather news cast on television, preventing interruptions during a layout toggle. |

    Want to test Virtual Background? Try the <a href="https://webdemo.agora.io/virtualBackground/index.html">online demo</a>.

    ## Prerequisites [#prerequisites-1]

    Ensure that you have implemented the [SDK quickstart](../../index) in your project.

    ## Implement virtual background [#implement-virtual-background-1]

    This section shows you how to add a virtual background to the local video.

    ### Check device compatibility [#check-device-compatibility-1]

    To avoid performance degradation or unavailable features when enabling Virtual Background on low-end devices, check whether the device supports the feature.

    ```swift
    guard agoraEngine.isFeatureAvailable(onDevice: .videoPreprocessVirtualBackground) else {
      // Device doesn't support virtual background
      return
    }
    ```

    ### Set a blurred background [#set-a-blurred-background-1]

    To blur the video background, use the following code:

    ```swift
    func blurBackground() {
      let virtualBackgroundSource = AgoraVirtualBackgroundSource()
      virtualBackgroundSource.backgroundSourceType = .blur
      virtualBackgroundSource.blurDegree = .high

      let segData = AgoraSegmentationProperty()
      segData.modelType = .agoraAi

      agoraEngine.enableVirtualBackground(true, backData: virtualBackgroundSource, segData: segData)
    }
    ```

    ### Set a color background [#set-a-color-background-1]

    To apply a solid color as the virtual background, use a hexadecimal color code.

    ```swift
    func colorBackground() {
      let virtualBackgroundSource = AgoraVirtualBackgroundSource()
      virtualBackgroundSource.backgroundSourceType = .color
      virtualBackgroundSource.color = convertColorToHex(.red)

      let segData = AgoraSegmentationProperty()
      segData.modelType = .agoraAi

      agoraEngine.enableVirtualBackground(true, backData: virtualBackgroundSource, segData: segData)
    }
    ```

    ### Set an image background [#set-an-image-background-1]

    To set a custom image as the virtual background, specify the absolute path to the image file.

    ```swift
    func imageBackground() {
      let virtualBackgroundSource = AgoraVirtualBackgroundSource()
      virtualBackgroundSource.backgroundSourceType = .img
      virtualBackgroundSource.source = Bundle.main.path(forResource: "background_ss", ofType: "jpg")

      let segData = AgoraSegmentationProperty()
      segData.modelType = .agoraAi

      agoraEngine.enableVirtualBackground(true, backData: virtualBackgroundSource, segData: segData)
    }
    ```

    ### Reset the background [#reset-the-background-1]

    To disable the virtual background and revert to the original video state, use the following code:

    ```swift
    agoraEngine.enableVirtualBackground(false, backData: nil, segData: nil)
    ```

    ## Reference [#reference-1]

    This section contains content that completes the information in this page, or points you to documentation that explains other aspects to this product.

    ### API reference [#api-reference-1]

    * [`isFeatureAvailable`](https://api-ref.agora.io/en/video-sdk/ios/4.x/documentation/agorartckit/agorartcenginekit/isfeatureavailable\(ondevice:\))

    * [`enableVirtualBackground`](https://api-ref.agora.io/en/video-sdk/ios/4.x/documentation/agorartckit/agorartcenginekit/enablevirtualbackground\(_\:backdata\:segdata:\))

    * [`AgoraVirtualBackgroundSource`](https://api-ref.agora.io/en/video-sdk/ios/4.x/documentation/agorartckit/agoravirtualbackgroundsource)

    * [`AgoraSegmentationProperty`](https://api-ref.agora.io/en/video-sdk/ios/4.x/documentation/agorartckit/agorasegmentationproperty)

    
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
