How can i make this signature view more clear and less blur?

jay patel

How can I make this signature view that should have optimal clarity when user drawing on it. I use this code to draw on image using CoreGraphics. Currently it coming like this and I want like another one. Help me with that. Below is the code snippet .

I am getting image like this link

Have This.

I want image to more clear like this link

Want this.

var lastPoint:CGPoint!
var isSwiping:Bool!
var isEditedImage = false
var lineWidth:CGFloat = 3.0
var lineOpacity:CGFloat = 1.0
var lineColor = UIColor.black

override func touchesBegan(_ touches: Set<UITouch>,
                          with event: UIEvent?){
    isSwiping    = false
    if let touch = touches.first{
        lastPoint = touch.location(in: signView)
    }
}

override func touchesMoved(_ touches: Set<UITouch>,
                           with event: UIEvent?){

    isSwiping = true
    if let touch = touches.first{
        let currentPoint = touch.location(in: signView)
        UIGraphicsBeginImageContext(self.signView.frame.size)
        self.signView.image?.draw(in: CGRect(x: 0, y: 0, width: self.signView.frame.size.width, height: self.signView.frame.size.height))
        UIGraphicsGetCurrentContext()?.move(to: CGPoint(x: lastPoint.x, y: lastPoint.y))
        UIGraphicsGetCurrentContext()?.addLine(to: CGPoint(x: currentPoint.x, y: currentPoint.y))
        UIGraphicsGetCurrentContext()?.setLineCap(CGLineCap.round)
        UIGraphicsGetCurrentContext()?.setLineWidth(lineWidth)
        UIGraphicsGetCurrentContext()?.setAlpha(lineOpacity)
        UIGraphicsGetCurrentContext()?.setStrokeColor(lineColor.cgColor)
        UIGraphicsGetCurrentContext()?.beginTransparencyLayer(auxiliaryInfo: nil)
        UIGraphicsGetCurrentContext()?.strokePath()
        UIGraphicsGetCurrentContext()?.endTransparencyLayer()
        self.signView.image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        lastPoint = currentPoint
        isEditedImage = true
    }
}

override func touchesEnded(_ touches: Set<UITouch>,
                           with event: UIEvent?){

    if(!isSwiping) {
        // This is a single touch, draw a point
        UIGraphicsBeginImageContext(self.signView.frame.size)
        self.signView.image?.draw(in: CGRect(x: 0, y: 0, width: self.signView.frame.size.width, height: self.signView.frame.size.height))
        UIGraphicsGetCurrentContext()?.setLineCap(CGLineCap.round)
        UIGraphicsGetCurrentContext()?.setLineWidth(lineWidth)
        UIGraphicsGetCurrentContext()?.setAlpha(lineOpacity)
        UIGraphicsGetCurrentContext()?.setStrokeColor(lineColor.cgColor)
        UIGraphicsGetCurrentContext()?.beginTransparencyLayer(auxiliaryInfo: nil)
        UIGraphicsGetCurrentContext()?.strokePath()
        UIGraphicsGetCurrentContext()?.endTransparencyLayer()
        self.signView.image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
}
matt

The amount of detail (vs. pixellation) in a graphics context depends on the context's scale. You are wrongly calling UIGraphicsBeginImageContext, so you are failing to provide a scale. Always call UIGraphicsBeginImageContextWithOptions so that you can provide a higher scale. (Don't make it too high, though; a higher-scale context requires exponentially more memory.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make the code in the view file with PHP and Laravel more clear?

From Dev

How can I refactor my kotlin code and make it more clear

From Java

How can I make a CSS glass/blur effect work for an overlay?

From Dev

how can i do left join (more or less) in datascript?

From Dev

How can I pipe colored tree result to less or more?

From Dev

How can I get a more clear name for Vagrant machine

From Dev

How can I make this Observable more reusable?

From Dev

How can I make this loop more efficient?

From Dev

How can I make this method more concise?

From Dev

How can I make this Makefile more generic?

From Dev

How can I make the button more visible?

From Dev

How can I make this loop more efficient?

From Dev

How can I make this code more elegant?

From Dev

How can I make a Read More Button?

From Dev

How to make a clear table view

From Dev

Less Blur with `Visual Effect View with Blur`?

From Dev

How can I make my generics code compatible with this method signature?

From Dev

how can I clear or set values in a digestive-functors view

From Dev

How can I make 'grunt less' automatically run autoprefixer?

From Dev

How can I simplify this Makefile to make it less repetitive?

From Dev

Qt: How can I make my exe 'weight' less

From Dev

How can I make string parsing in Python less unwieldy?

From Dev

How can I make hot corners less sensitive?

From Dev

How can I simplify this Makefile to make it less repetitive?

From Dev

In Rust, how can I make this code less repetitive?

From Dev

How can i make this Javascript code less repetitve?

From Dev

How can I make my while loop less stressful on the browser?

From Dev

How can i make a button to clear one of my fields in a form?

From Dev

How can I make calendar view in Swift

Related Related

  1. 1

    How can I make the code in the view file with PHP and Laravel more clear?

  2. 2

    How can I refactor my kotlin code and make it more clear

  3. 3

    How can I make a CSS glass/blur effect work for an overlay?

  4. 4

    how can i do left join (more or less) in datascript?

  5. 5

    How can I pipe colored tree result to less or more?

  6. 6

    How can I get a more clear name for Vagrant machine

  7. 7

    How can I make this Observable more reusable?

  8. 8

    How can I make this loop more efficient?

  9. 9

    How can I make this method more concise?

  10. 10

    How can I make this Makefile more generic?

  11. 11

    How can I make the button more visible?

  12. 12

    How can I make this loop more efficient?

  13. 13

    How can I make this code more elegant?

  14. 14

    How can I make a Read More Button?

  15. 15

    How to make a clear table view

  16. 16

    Less Blur with `Visual Effect View with Blur`?

  17. 17

    How can I make my generics code compatible with this method signature?

  18. 18

    how can I clear or set values in a digestive-functors view

  19. 19

    How can I make 'grunt less' automatically run autoprefixer?

  20. 20

    How can I simplify this Makefile to make it less repetitive?

  21. 21

    Qt: How can I make my exe 'weight' less

  22. 22

    How can I make string parsing in Python less unwieldy?

  23. 23

    How can I make hot corners less sensitive?

  24. 24

    How can I simplify this Makefile to make it less repetitive?

  25. 25

    In Rust, how can I make this code less repetitive?

  26. 26

    How can i make this Javascript code less repetitve?

  27. 27

    How can I make my while loop less stressful on the browser?

  28. 28

    How can i make a button to clear one of my fields in a form?

  29. 29

    How can I make calendar view in Swift

HotTag

Archive