登录
  • 欢迎访问 Sharezer Blog

使用NSBezierPath在NSImageView中画线

IOS sharezer 2880次浏览 已收录 0个评论

if captureFilePath != nil{
    let image: NSImage = getImageFromURL(url: captureFilePath!)!
    image.lockFocus()
    
    NSColor.white.setStroke()
    
    let height: Int = Int(image.size.height)
    let width: Int = Int(image.size.width)
    
    let lineWidth = CGFloat(height > width ? height / 200  + 1: width / 200 + 1)
    
    NSBezierPath.setDefaultLineWidth(lineWidth)
    NSBezierPath.strokeLine(from: NSPoint.init(x: Int(left.stringValue)!, y: 0), to: NSPoint.init(x: Int(left.stringValue)!, y: height))
    NSBezierPath.strokeLine(from: NSPoint.init(x: width - Int(right.stringValue)!, y: 0), to: NSPoint.init(x: width - Int(right.stringValue)!, y: height))
    NSBezierPath.strokeLine(from: NSPoint.init(x: 0, y: Int(bottom.stringValue)!), to: NSPoint.init(x: width, y: Int(bottom.stringValue)!))
    NSBezierPath.strokeLine(from: NSPoint.init(x: 0, y: height - Int(top.stringValue)!), to: NSPoint.init(x: width, y: height - Int(top.stringValue)!))
    
    image.unlockFocus()
    sourceImage.image = image
}

效果如下图,其中白色的线就是用NSBezierPath画的

使用NSBezierPath在NSImageView中画线


Sharezer , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用NSBezierPath在NSImageView中画线
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址