사용자가 그림을 그릴 때 최적의 선명도를 가져야하는이 서명보기를 어떻게 만들 수 있습니까? CoreGraphics
을 사용하여 이미지에 그릴 때이 코드를 사용합니다. 현재이 같은오고 다른 싶습니다. 그걸 도와 줘. 아래는 코드 스 니펫입니다.이 서명보기를 더 선명하고 덜 흐리게 만들 수있는 방법은 무엇입니까?
나는이 링크
같은 이미지를 얻고있다.
나는이 링크
같은 더 명확한 이미지를 원한다.
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()
}
}
https://github.com/GJNilsen/YPDrawSignatureView를 사용하십시오. 더 좋다고 생각합니다. –
github에 많은 광고 모음이 있습니다. 이 것이 다른 것과 같이 달리는 경우에 그러나 좋을. –
좋을지도 모릅니다. 나는 단지 내가 사용한 것을 제안했다. 필요한 경우 코드를 참조하고 수정할 수 있습니다. –