# Replace the background in Android

> Replace the Camera2 background with a color, Bitmap, or local looping video through Nosmai segmentation.

> For AI agents: the complete documentation index is at https://nosmai.com/llms/effects.txt

Product: Nosmai Effects
Group: guide
Source: https://nosmai.com/docs/effects/guides/background/replace-the-background/android/

## Prerequisites

- A working [Android quickstart](/docs/effects/quickstart/android/)
- Advanced filters enabled for the project
- A decoded `Bitmap` or readable local video path

## Replace with an image

```java
NosmaiBackgroundSegmentationConfig config =
    new NosmaiBackgroundSegmentationConfig(
        NosmaiBackgroundSegmentationConfig.Mode.IMAGE
    );
config.replacementImage = backgroundBitmap;

NosmaiEffects.setBackgroundSegmentation(config);
```

For a color, use `Mode.COLOR` and set an Android ARGB integer in
`replacementColor`. For video, use `Mode.VIDEO` and set a readable file path or
content URI in `replacementVideoPath`.

## Change or clear it

```java
NosmaiEffects.clearBackgroundSegmentation();
```

Do not recycle the supplied bitmap while the background configuration is
active.

## Quality guidance

Use even front lighting and an asset close to the preview aspect ratio. Test
hair, glasses, quick motion, low light, and both camera facings on the lowest
supported device.

## Verify it worked

The source background should be replaced without restarting Camera2. Pause and
resume the app once to confirm the configuration and camera lifecycle recover.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| Background stays unchanged | Pipeline is not ready or advanced filters are unavailable | Check readiness and project capabilities |
| Video fails | Path or content URI is not readable | Resolve permission and pass a local readable value |
| Preview slows | Segmentation and camera resolution exceed the device budget | Use 30 FPS, start at 720p, and test a Release build |

## Next steps

- [Blur the background in Android](/docs/effects/guides/background/blur-the-background/android/)
- [Record video in Android](/docs/effects/guides/output/record-video/android/)
- [Review Android requirements](/docs/effects/platforms/android/)

## References

- [Android quickstart](/docs/effects/quickstart/android/)
- [Rendering pipeline](/docs/effects/concepts/how-the-pipeline-works/)
