Some NSControl don't return an "Image"

This code works for almost every macOS control but it seems NS

private func draw_CTRL_SEGCTRL() {
        let tempCtrl          = uxSEGMENTEDCONTROL(frame:zCTRL_FRAME)
        tempCtrl.segments     = "Seg 1|Seg 2|Seg 3|1"
        tempCtrl.alphaValue   = 1
        tempCtrl.needsLayout  = true
        tempCtrl.needsDisplay = true
        takeSnapShot(tempCtrl)
    }

above creates a NSSegmentedControl and populates some default properties

        if let rep = tempCtrl.bitmapImageRepForCachingDisplay(in: tempCtrl.bounds) {
            tempCtrl.cacheDisplay(in:    tempCtrl.bounds, to: rep)
            osCtrlImage = NSImage(size:  tempCtrl.bounds.size)
            osCtrlImage!.addRepresentation(rep)
        }
    }

above is supposed to render the passed control, and create an NSImage of it, like I mentioned this works for everything else. For Segment it just returns a clear rectangle of the specified size,

NSSegmentedControl is not based on NSView like most everything else is…so the solution is to embed in a NSView BEFORE taking snapshot

 private func draw_CTRL_SEGCTRL() {
        let tempCtrl          = uxSEGMENTEDCONTROL(frame:zCTRL_FRAME)
        tempCtrl.segments     = "Seg 1|Seg 2|Seg 3|1"
        tempCtrl.alphaValue   = 1
        tempCtrl.needsLayout  = true
        tempCtrl.needsDisplay = true
        let container = uxVIEW(frame:tempCtrl.frame)
        container.addSubview(tempCtrl)
        takeSnapShot(container)
    }

For me this code work

extension NSView

{

func getScreenshot() -> NSImage

{

    if let rep = self.bitmapImageRepForCachingDisplay(in: self.bounds)

    {

        rep.size = self.bounds.size

        self.cacheDisplay(in: self.bounds, to: rep)

        let img = NSImage(size: rep.size)

        img.addRepresentation(rep)

    

        return img

    }

    return NSImage()

}

but does it work with NSSegmentedControl , or Horz/Vertical Scrollbars, or tabbed panel
because those I will bet won’t work, as this code is almost identical to my original code which does work with every other control, except the ones named above.

Work well for me.

I use this code for my playgrndCreator in mac App Store (GUI Creator for Playground)

https://apps.apple.com/us/app/playgrndcreator/id6444596670

But if you have solded the problem it’s OK