Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let filter = CIFilter(name: "CIPerspectiveCorrection")!
- let width = CGFloat(image.size.width)
- let height = CGFloat(image.size.height)
- var topLeft = CGPoint(x: rectangle.topLeft.x * width, y: rectangle.topLeft.y * height)
- var topRight = CGPoint(x: rectangle.topRight.x * width, y: rectangle.topRight.y * height)
- var bottomLeft = CGPoint(x: rectangle.bottomLeft.x * width, y: rectangle.bottomLeft.y * height)
- var bottomRight = CGPoint(x: rectangle.bottomRight.x * width, y: rectangle.bottomRight.y * height)
- let scaleH = height/width
- print(width)
- print(height)
- print(topLeft)
- print(topRight)
- print(bottomLeft)
- print(bottomRight)
- func checkRectangle() -> Bool{
- var returnValue = true
- if topRight.y > height - scaleH{
- returnValue = false
- }
- if topLeft.y > height - scaleH{
- returnValue = false
- }
- if bottomLeft.y < scaleH{
- returnValue = false
- }
- if bottomRight.y < scaleH{
- returnValue = false
- }
- if topRight.x > width - 1{
- returnValue = false
- }
- if topLeft.x < 1{
- returnValue = false
- }
- if bottomLeft.x < 1{
- returnValue = false
- }
- if bottomRight.x > width - 1{
- returnValue = false
- }
- return returnValue
- }
- repeat{
- topLeft.y += scaleH
- topLeft.x -= 1
- topRight.y += scaleH
- topRight.x += 1
- bottomRight.y -= scaleH
- bottomRight.x += 1
- bottomLeft.y -= scaleH
- bottomLeft.x -= 1
- }while(checkRectangle())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement