Nosmai  Effects Nosmai  Moderation Nosmai Try-ons coming soon
Docs menu Android
How-to guide

Replace the background in Android

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

Platform Android SDK version 3.0.4 Updated Aug 22, 2026 Time 7 min

Prerequisites

  • A working Android quickstart
  • Advanced filters enabled for the project
  • A decoded Bitmap or readable local video path

Replace with an image

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

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

SymptomCauseFix
Background stays unchangedPipeline is not ready or advanced filters are unavailableCheck readiness and project capabilities
Video failsPath or content URI is not readableResolve permission and pass a local readable value
Preview slowsSegmentation and camera resolution exceed the device budgetUse 30 FPS, start at 720p, and test a Release build

Next steps

References

Was this page helpful?

Your response helps us prioritize documentation improvements.

Nosmai

An AR and AI company. Founded on the idea that the next decade of software will be visual, and that the tools for it should be within reach of anyone building.

Newsletter

Product updates and release notes. No spam.

© 2026 nosmai, inc · all rights reserved