Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to merge with Transparent image #2

Open
pawaom opened this issue Feb 2, 2022 · 0 comments
Open

how to merge with Transparent image #2

pawaom opened this issue Feb 2, 2022 · 0 comments

Comments

@pawaom
Copy link

pawaom commented Feb 2, 2022

how to merge with Transparent image

When we us this code with normal image it works fine

**
* Uses the detected segmentation mask to overlay the background image
*/
fun generateMaskBgImage(image: Bitmap, bg: Bitmap): Bitmap {
val bgBitmap = Bitmap.createBitmap(image.width, image.height, image.config)

    for (y in 0 until maskHeight) {
        for (x in 0 until maskWidth) {
            val bgConfidence = ((1.0 - maskBuffer.float) * 255).toInt()
            var bgPixel = bg.getPixel(x, y)
            bgPixel = ColorUtils.setAlphaComponent(bgPixel, bgConfidence)
            bgBitmap.setPixel(x, y, bgPixel)
        }
    }
    maskBuffer.rewind()
    return mergeBitmaps(image, bgBitmap)
}

}

however when we try to merge it with transparent image it creates a black background instead of transparent background how can we merge and keep background transparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant