Created
March 14, 2023 13:50
-
-
Save Rohit-554/65b0f2f4dd078d1fb498839be41a9f41 to your computer and use it in GitHub Desktop.
ReverseFunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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