Combining two bitmap image (side by side)

前端 未结 3 1040
醉梦人生
醉梦人生 2020-12-04 22:24

Can any one help to combine two bitmap images into single bitmap

in android (Side by side).

Thanks, Yuvaraj

3条回答
  •  半阙折子戏
    2020-12-04 23:17

    I ended up modifying xil3's answer into a kotlin extension function, maybe it will be useful to someone. In my case I wanted the images stacked vertically

    fun Bitmap?.combine(b: Bitmap?): Bitmap? =
    when {
        b == null || this == null -> {
            this ?: b
        } else -> {
            val cs = Bitmap.createBitmap(
                max(this.width, b.width),
                this.height + b.height,
                Bitmap.Config.ARGB_8888
            )
            val canvas = Canvas(cs)
            canvas.drawBitmap(this, 0f, 0f, null)
            canvas.drawBitmap(b, 0f, this.height.toFloat(), null)
            cs
        }
    }
    

提交回复
热议问题