Hanushka Suren
Hanushka Suren

Reputation: 793

Crop an image into a rectangle shape when the cropping points are on any shape which has 4 points - IOS/Swift

In my project, I want to set 4 cropping points manually on an image and crop that image according to set points. For example have a look on below image.

enter image description here

Like this, all I want is to crop the image according to that path and after cropping it should be a rectangle. This is just like image cropping in CamScanner IOS application. If anyone have any idea how to do this any help would be highly appreciated.

Upvotes: 2

Views: 3892

Answers (2)

Wu Baiquan
Wu Baiquan

Reputation: 129

I think you need geometric_transformations.

If you plan to use opencv, here is a good example: http://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/

Upvotes: 1

Nitin Gohel
Nitin Gohel

Reputation: 49730

Here are found very nice github project that have same funtionality what you want but this is in Objective-C might be you can convert this code in to swift check the link following:

https://github.com/jberlana/JBCroppableView

It's output is:

enter image description here

UPDATE

I just made one Demo in Swift using JBCroppableView Objective-C class implements in Swift. Download from the following and use as per your requirement.

https://github.com/nitingohel/NGCropview

The Combination of Swift + Objective-C

OUTPUT

enter image description here

Upvotes: 3

Related Questions