Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- custSign.setOnTouchListener { v, event ->
- xCust = event.x
- yCust = event.y
- when (event.action) {
- MotionEvent.ACTION_DOWN -> {
- // val layoutParams = FrameLayout.LayoutParams(
- // v.layoutParams.width,
- // v.layoutParams.height
- // )
- // layoutParams.setMargins(
- // (event.rawX - v.width / 2).toInt(), // margin left
- // (event.rawY - v.height / 2).toInt(), // margin top
- // (layoutParams.width - (event.rawX + v.width / 2)).toInt(), // margin right
- // (layoutParams.height - (event.rawY + v.height / 2)).toInt()
- // )
- // v.layoutParams = layoutParams
- // v.performClick()
- }
- MotionEvent.ACTION_MOVE -> {
- val layoutParams = FrameLayout.LayoutParams(
- v.layoutParams.width,
- v.layoutParams.height
- )
- layoutParams.setMargins(
- (event.rawX - v.width / 2).toInt(), // margin left
- (event.rawY - v.height / 2).toInt(), // margin top
- (layoutParams.width - (event.rawX + v.width / 2)).toInt(), // margin right
- (layoutParams.height - (event.rawY - v.height / 2)).toInt()
- )
- Log.d("TotalMargin", "${v.width/2} : ${v.height/2}")
- v.layoutParams = layoutParams
- v.performClick()
- }
- }
- true
- }
- private fun mergeBitmap(file: File, collSign: Bitmap, custSign: Bitmap): Bitmap? {
- return try {
- val bitmap = loadAndRenderPdfToImage(file)
- // val result = bitmap?.let { bitmapOverlayToCenter(it, collSign) }
- val bitmap1Width = bitmap?.width
- val bitmap1Height = bitmap?.height
- val bitmap2Width = collSign.width
- val bitmap2Height = collSign.height
- val bitmap3Width = custSign.width
- val bitmap3Height = custSign.height
- // val marginLeft = (bitmap1Width * 0.5 - bitmap2Width * 0.5).toFloat()
- // val marginTop = (bitmap1Height * 0.5 - bitmap2Height * 0.5).toFloat()
- // val finalXColl: Float = (bitmap1Width - bitmap2Width).toFloat()
- // val finalYColl: Float = (bitmap1Height - bitmap2Height).toFloat()
- // val finalXColl: Float = (bitmap1Width?.div(bitmap2Width))?.toFloat()!!
- // val finalYColl: Float = (bitmap1Height?.div(bitmap2Height))?.toFloat()!!
- // val finalXCust: Float = (bitmap1Width.div(bitmap3Width)).toFloat()
- // val finalYCust: Float = (bitmap1Height.div(bitmap3Height)).toFloat()
- val finalBitmap = Bitmap.createBitmap(bitmap1Width as Int, bitmap1Height as Int, bitmap.config)
- val canvas = Canvas(finalBitmap)
- bitmap.let { canvas.drawBitmap(it, Matrix(), null) }
- // canvas.drawBitmap(collSign, xColl * finalXColl , yColl * finalYColl, null)
- // canvas.drawBitmap(custSign, xCust * finalXCust, yCust * finalYCust, null)
- canvas.drawBitmap(collSign, xColl * 1.5f , yColl * 1.82f, null)
- canvas.drawBitmap(custSign, xCust * 1.95f, yCust * 1.82f, null)
- // bitmap = bitmap?.let {
- // Bitmap.createScaledBitmap(
- // it,
- // bitmap!!.width,
- // bitmap!!.height,
- // false
- // )
- // }
- // val collSignBitmap = Bitmap.createScaledBitmap(collSign, 100, 100, false)
- // val custSignBitmap = Bitmap.createScaledBitmap(custSign, 100, 100, false)
- // val result = Bitmap.createBitmap(bitmap!!.width, bitmap.height, bitmap.config)
- // val canvas = Canvas(result)
- // canvas.drawBitmap(bitmap, Matrix(), null)
- // val finalXColl: Float = bitmap.width.toFloat()/contentFinal.width.toFloat()
- // val finalYColl: Float = bitmap.height.toFloat()/contentFinal.height.toFloat()
- // canvas.drawBitmap(collSignBitmap, xColl, yColl, Paint())
- // canvas.drawBitmap(custSignBitmap, xCust, yCust, Paint())
- Log.d("CreateBitmap", "Success $finalBitmap")
- // content.visibility = View.GONE
- collSign.recycle()
- custSign.recycle()
- // contentFinal.setImageBitmap(finalBitmap)
- imageCollSign = null
- imageCustSign = null
- finalBitmap
- } catch (e: Exception) {
- e.printStackTrace()
- Utils.showInfoMessage(this, "Error occurred while merging image", saveAndCreateImageToPdf)
- null
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement