1

I am making sharing feature like youtube music shares image to instagram story. Everything works fine, but I can't make the curved edge.

enter image description here

The transparent part at the end of the edge changes to black like the below picture.

enter image description here

I tried

  • add bitmap.setHasAlpha(true)
  • custom shading with BitmapShader
  • set AntiAlias true

My code is like this

    fun onCreate() {
       val changedBitmap = cardViewToBitmap(binding.clCardview)
       shareImage(changedBitmap)
    }

    fun cardViewToBitmap(cardView: View): Bitmap {
        val bitmap = Bitmap.createBitmap(cardView.width, cardView.height, Bitmap.Config.ARGB_8888)
        bitmap.eraseColor(Color.TRANSPARENT)
        bitmap.setHasAlpha(true)
        val canvas = Canvas(bitmap)

        val radius = 20f
        val path = Path()
        path.addRoundRect(0f, 0f, cardView.width.toFloat(), cardView.height.toFloat(), radius, radius, Path.Direction.CW)
        canvas.clipPath(path)

        cardView.draw(canvas)
        return bitmap
    }

I found that instagram doesn't support transparent background. How can I do it?

Isaac Lee
  • 466
  • 1
  • 3
  • 15

0 Answers0