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
网友评论