Android crop image like camscanner

前端 未结 2 1444
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-25 08:46

I am developing a project which requires the image crop feature like camscanner android application,when a picture is taken and when user clicks the crop button, a rectangle

相关标签:
2条回答
  • 2020-12-25 09:05

    I had a similar requirement and I too didn't find any concrete solution similar to CamScanner, so I have taken the challenge and have implemented a scan library (on top of OpenCV, rich image processing library) similar to CamScanner which can be easily integrated into an existing application, using the library you will be able to select the exact edges in whatever angle and crop the document accordingly from the selected 4 edges and change the perspective transformation of the cropped image.

    Github link of the Android ScanLibrary: https://github.com/jhansireddy/AndroidScannerDemo

    enter image description here

    0 讨论(0)
  • 2020-12-25 09:25

    thanks @jhansi for this amazing library but the problem of this library(Android Scanner Library) is the image orientation is always 90 degree rotated, we can solve it like this.

    Solution in Kotlin

    In OnActivityResult it gives you bitmap and this bitmap you can pass to "Bitmap.roate" method.

    Use it like this: val rotatedBitmap=bitmap.rotate(90f) imageView.setImageBitmap(rotatedBitmap)

    Paste this method in your activity: fun Bitmap.rotate(degrees: Float): Bitmap { val matrix = Matrix().apply { postRotate(degrees) } return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true) }

    0 讨论(0)
提交回复
热议问题