我怎样才能让这个签名视图更清晰,更少模糊?

杰伊·帕特尔

当用户在其上绘图时,如何制作应具有最佳清晰度的签名视图。我使用此代码使用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()
    }
}
哑光

图形上下文中的细节量(相对于像素化)取决于上下文的scale. 您错误地调用了UIGraphicsBeginImageContext,因此您没有提供秤。总是打电话,UIGraphicsBeginImageContextWithOptions这样你就可以提供更高的规模。(不过不要让它太高;更大规模的上下文需要成倍增加的内存。)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我怎样才能让我的班级识别这个枚举?

来自分类Dev

我怎样才能让这个 .slideToggle 方法工作?

来自分类Dev

MYSQL - 我怎样才能让这个左连接工作?

来自分类Dev

我怎样才能让这个功能继续运行

来自分类Dev

我怎样才能让 Jquery 为这个页面工作

来自分类Dev

我怎样才能让这个视差滑块自动滑动

来自分类Dev

我怎样才能更简化这个?

来自分类Dev

我怎样才能让Jelastic入睡?

来自分类Dev

我怎样才能让 Listview 适合?

来自分类Dev

我怎样才能让cardview消失?

来自分类Dev

我怎样才能让这个gsub函数为我工作?

来自分类Dev

我怎样才能让我的应用程序运行并解决这个错误

来自分类Dev

我怎样才能让这个表格以我的页面为中心?

来自分类Dev

我怎样才能让这个 javascript 工作不止一次?

来自分类Dev

我怎样才能让这个返回 promise 的函数不阻塞其他代码?

来自分类Dev

我怎样才能让这个图表在本地呈现?(D3.js)

来自分类Dev

我怎样才能让谷歌地图视图总是出现在我的布局底部?

来自分类Dev

我怎样才能让我的脚本改变我的背景?

来自分类Dev

我怎样才能简化这个?

来自分类Dev

我怎样才能阅读这个xml?

来自分类Dev

我怎样才能画这个边界?

来自分类Dev

我怎样才能生成这个?

来自分类Dev

我怎样才能制作这个套装?

来自分类Dev

我怎样才能加快这个功能

来自分类Dev

我怎样才能摆脱这个循环?

来自分类Dev

我怎样才能让gpg只列出我的钥匙?

来自分类Dev

我怎样才能让我的页脚粘在底部?

来自分类Dev

我怎样才能让我的网络接收 mysql 数据

来自分类Dev

我怎样才能让我的会话 ID 工作

Related 相关文章

热门标签

归档