Export canvas context to image in swiftUI OSX

I have built a painting app for OSX and now i don't know how to convert the canvas to image