Closed fukemy closed 6 years ago
Can you tell me more about use case? I can make a separate branch with this functionality, but I just don't understand how to make a handler so that it does not interfere with the dragging of the corners
sorry let i introduce my ideal. First I have a square with 4 corner.
after pull the polygon will be like that:
may be we can make more corner by pull from center of line.
let see my project i editted, i can not pull to make new corner, but i can add new corner in center of line when click in to one corner
https://vimeo.com/user84971345/review/285717526/7e9d06f329
This not the great function but all I can do now TT^TT. P/s: I just upload to video server, u need wait for a wait for video is available.
that is method i used to add new point into corner i clicked + the next corner:
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
.....
if mode == .addPointOnly {
let startP = cornerLocations![cornerOnTouch]
var endP : CGPoint
var indexToAdd : Int = 0
if cornerOnTouch == (cornerLocations?.count)! - 1 {
// clicked corner is the last item in 'corner list' -> endP will be the first corner
endP = cornerLocations![0]
}else {
endP = cornerLocations![cornerOnTouch + 1]
}
indexToAdd = cornerOnTouch + 1
let centerP : CGPoint = CGPoint(x: (startP.x + endP.x) / 2, y: (startP.y + endP.y) / 2)
print("startP: \(startP)")
print("endP: \(endP)")
print("centerP: \(centerP)")
print("indexToAdd: \(indexToAdd)")
delegate?.addPoint(newP: centerP, indexToAdd: indexToAdd)
}
}
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
guard mode == .dragging else{
return
}
....
}
when delegate called. I renew the SECorverView then config again:
var cornor : NSMutableArray = []
// init corner point list....
extension ViewController : SECropViewDelegate {
func addPoint(newP: CGPoint, indexToAdd: Int) {
cornor.insert(newP, at: indexToAdd)
cropView.removeFromSuperview()
cropView = SECropView()
cropView.delegate = self
cropView.configureWithCorners(corners: cornor as! [CGPoint], on: imageView)
}
// when end drag corner, i update location of this corner to list and renew all
func updatePoint(newP: CGPoint, indexToAdd: Int) {
cornor.replaceObject(at: indexToAdd, with: newP)
cropView.removeFromSuperview()
cropView = SECropView()
cropView.delegate = self
cropView.configureWithCorners(corners: cornor as! [CGPoint], on: imageView)
}
}
Got it, I'll add it in the next couple of days
hmm. May be it's very hard. I am sorry for asking too hard function
@jonasbeckers jo @Idomo id can you?
@fukemy Umm, I didn't understood, why would you want to make shape like this if you are scanning documents?
Hi. As you know, some documents may be torned, or by design... that make it's not be in Quadrangle. So we need more 4 points to detect the documents.
@fukemy It is very rare that someone will scan document with more than 4 points. Anyway, eventually you'll have to save the image as rectangle with 4 points, so the cut background will be black/withe or the surface that the user scan the document on (table etc.).
tks. i know it, but i just want to catch all situations. May be in future some one will ask the same question like this, but not now. So i will close this issue.
lol. First give u a very bigggggg thanks. because it took long tine to found your lib. I want to ask that question: can i drag from point in a line, that create new corner from this then we can drag it as normally?