Advertisement
jerrytank9

Untitled

Jun 15th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.06 KB | None | 0 0
  1.             val stickerBitmap = stickerView.drawToBitmap().trimBorders(Color.argb(0, 0, 0, 0))
  2.             val originalBitmap = fa
  3.             var purePageView = pageView.drawToBitmap()
  4.             val displayedBitmap = pageView.drawToBitmap().trimBorders(Color.argb(0, 0, 0, 0))
  5.             var (h1, w1) = stickerView.bounds
  6.             w1 -= binding.toolbar.height + binding.pageView.marginTop
  7.             h1 -= (binding.pageView.marginStart + binding.pageView.marginEnd + (purePageView.width - displayedBitmap.width)/2)
  8.             val x = originalBitmap.height
  9.             val y = originalBitmap.width
  10.             val x1 = displayedBitmap.height
  11.             val y1 = displayedBitmap.width
  12.             val x2 = stickerBitmap.height
  13.             val y2 = stickerBitmap.width
  14.             val h = h1 * y / y1.toFloat()
  15.             val w = x * w1 / x1.toFloat()
  16.             val x3 = x2 * x / x1
  17.             val y3 = y2 * y / y1
  18.             val scaledSticker2 = Bitmap.createScaledBitmap(stickerBitmap, y3, x3, true)
  19.             val resultBitmap = Bitmap.createBitmap(
  20.                 originalBitmap.width,
  21.                 originalBitmap.height,
  22.                 Bitmap.Config.ARGB_8888
  23.             )
  24.             val resultCanvas = Canvas(resultBitmap)
  25.             val paint = Paint()
  26.             var cf = PorterDuffColorFilter(Color.argb(255,0,255,0), PorterDuff.Mode.SRC_IN)
  27.             paint.colorFilter = cf
  28.             resultCanvas.drawBitmap(originalBitmap, 0f, 0f, null)
  29.  
  30.             cf = PorterDuffColorFilter(Color.argb(255,0,255,255), PorterDuff.Mode.SRC_IN)
  31.             paint.colorFilter = cf
  32.             resultCanvas.drawBitmap(scaledSticker2, h + binding.pageView.marginStart, w+abs(binding.pageView.marginTop-binding.pageView.marginBottom), paint)
  33.  
  34.             cf = PorterDuffColorFilter(Color.argb(255,0,123,123), PorterDuff.Mode.SRC_IN)
  35.             paint.colorFilter = cf
  36.             resultCanvas.drawBitmap(scaledSticker2, h + abs(binding.pageView.marginStart-binding.pageView.marginEnd), w+abs(binding.pageView.marginTop-binding.pageView.marginBottom), paint)
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement