Skip to content

Instantly share code, notes, and snippets.

@Rohit-554
Created March 14, 2023 13:50
Show Gist options
  • Select an option

  • Save Rohit-554/65b0f2f4dd078d1fb498839be41a9f41 to your computer and use it in GitHub Desktop.

Select an option

Save Rohit-554/65b0f2f4dd078d1fb498839be41a9f41 to your computer and use it in GitHub Desktop.
ReverseFunction
fun reverseDistortImage(distortedBitmap: Bitmap, originalBitmap: Bitmap): Bitmap {
val width = distortedBitmap.width
val height = distortedBitmap.height
val reversedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val distortionFactor = 0.02f // Adjust the distortion factor as needed
val xDistortion = (width * distortionFactor).toInt()
val yDistortion = (height * distortionFactor).toInt()
for (x in 0 until width) {
for (y in 0 until height) {
val distX = x - xDistortion * sin(y.toDouble() / height * 2 * PI).toFloat()
val distY = y - yDistortion * cos(x.toDouble() / width * 2 * PI).toFloat()
if (distX >= 0 && distX < width && distY >= 0 && distY < height) {
val color = distortedBitmap.getPixel(distX.toInt(), distY.toInt())
reversedBitmap.setPixel(x, y, color)
}
}
}
imageview?.setImageBitmap(reversedBitmap)
return distortedBitmap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment