Skip to content

how to merge with Transparent image #2

@pawaom

Description

@pawaom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions