Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android crop image like camscanner

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 overlay should be shown as in camscanner. Where the rectangle path can be stretched to any angle and can perform crop.please do help me with a solution.

I was referring to https://github.com/edmodo/cropper . but this as only rectangle overlay with 4 points.please do help me if any one has a link or solution!!

like image 721
Robin prash Avatar asked Sep 20 '13 18:09

Robin prash


People also ask

How do I enable auto crop in Camscanner?

Scan SettingsSelect "Auto crop image", to scan and crop images automatically. Click "Enhance mode", to select a default enhance mode for the images. Click "No enhance", to keep the original images.


2 Answers

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

like image 120
jhansi Avatar answered Sep 19 '22 15:09

jhansi


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) }

like image 25
syed dastagir Avatar answered Sep 20 '22 15:09

syed dastagir