NSView 转换图片

2019-05-16  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读