Transparent background on iOS

Since the parts other than the foreground (people, etc.) are transparent, it can be used for background composition.



Acquire mask images using segmentation models such as the DeepLab v3 model distributed by Apple.
Please refer to this article.

Create a transparent image with the same size as the original image.
Since the “non-transparent area” is specified in the argument of settingAlphaOne, specify zero to acquire a fully transparent image.

let transparentImage = originalCIImage.settingAlphaOne(in:

Foreground = original image, background = transparent image, mask image = mask image of the object you want to keep, and combine with CIFilter.

let compositeImage = CIFilter(name: "CIBlendWithMask", parameters: [
kCIInputImageKey: originalCIImage,

Prepare a background image and combine it again to create a composite image.




Request for work:

Freelance iOS developer. You can ask me for a job from any country.