Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val stickerBitmap = stickerView.drawToBitmap().trimBorders(Color.argb(0, 0, 0, 0))
- val originalBitmap = fa
- var purePageView = pageView.drawToBitmap()
- val displayedBitmap = pageView.drawToBitmap().trimBorders(Color.argb(0, 0, 0, 0))
- var (h1, w1) = stickerView.bounds
- w1 -= binding.toolbar.height + binding.pageView.marginTop
- h1 -= (binding.pageView.marginStart + binding.pageView.marginEnd + (purePageView.width - displayedBitmap.width)/2)
- val x = originalBitmap.height
- val y = originalBitmap.width
- val x1 = displayedBitmap.height
- val y1 = displayedBitmap.width
- val x2 = stickerBitmap.height
- val y2 = stickerBitmap.width
- val h = h1 * y / y1.toFloat()
- val w = x * w1 / x1.toFloat()
- val x3 = x2 * x / x1
- val y3 = y2 * y / y1
- val scaledSticker2 = Bitmap.createScaledBitmap(stickerBitmap, y3, x3, true)
- val resultBitmap = Bitmap.createBitmap(
- originalBitmap.width,
- originalBitmap.height,
- Bitmap.Config.ARGB_8888
- )
- val resultCanvas = Canvas(resultBitmap)
- val paint = Paint()
- var cf = PorterDuffColorFilter(Color.argb(255,0,255,0), PorterDuff.Mode.SRC_IN)
- paint.colorFilter = cf
- resultCanvas.drawBitmap(originalBitmap, 0f, 0f, null)
- cf = PorterDuffColorFilter(Color.argb(255,0,255,255), PorterDuff.Mode.SRC_IN)
- paint.colorFilter = cf
- resultCanvas.drawBitmap(scaledSticker2, h + binding.pageView.marginStart, w+abs(binding.pageView.marginTop-binding.pageView.marginBottom), paint)
- cf = PorterDuffColorFilter(Color.argb(255,0,123,123), PorterDuff.Mode.SRC_IN)
- paint.colorFilter = cf
- resultCanvas.drawBitmap(scaledSticker2, h + abs(binding.pageView.marginStart-binding.pageView.marginEnd), w+abs(binding.pageView.marginTop-binding.pageView.marginBottom), paint)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement