美文网首页
NSView 转换图片

NSView 转换图片

作者: 搞好关系 | 来源:发表于2019-05-16 22:47 被阅读0次

macOS NSView 转化出图片数据


t
   self.view.wantsLayer = true
        self.view.layer?.borderColor = NSColor.red.cgColor
        self.view.layer?.borderWidth = 5
        let rep : NSBitmapImageRep? = self.view.bitmapImageRepForCachingDisplay(in: self.view.bounds)
 self.view.cacheDisplay(in: self.view.bounds, to: rep!)
        let data =  rep?.representation(using: NSBitmapImageRep.FileType.png, properties: [:])
        do{
         try   data?.write(to: URL.init(fileURLWithPath: picPath+"/xx.png"))
        }catch{
            print(error)
        }
        
xx.png

相关文章

网友评论

      本文标题:NSView 转换图片

      本文链接:https://www.haomeiwen.com/subject/lvcgaqtx.html