Returns a composite image based on a dynamically generated list of windows.


func CGWindowListCreateImage(_ screenBounds: CGRect, _ listOption: CGWindowListOption, _ windowID: CGWindowID, _ imageOption: CGWindowImageOption) -> CGImage?



The rectangle that you want to capture. The coordinates of the rectangle must be specified in screen coordinates, where the screen origin is in the upper-left corner of the main display and y-axis values increase downward. Specify null to indicate the minimum rectangle that encloses the specified windows. Specify infinite to capture the entire desktop area.


The options describing which windows to include in the image. Typical options let you choose all windows or windows above or below the window specified in the windowID parameter. For more information, see Window List Option Constants.


The ID of the window to use as a reference point when determining which other windows to include in the image. For options that do not require a reference window, this parameter can be kCGNullWindowID.


The options that determine which parts of the window to capture. If you specified null for the screenBounds parameter, these options affect the resulting bounding box used for the image. For example, if you include a window’s screen effects in the image, the bounding box may need to be slightly larger to accommodate those effects. For a list of possible options, see Window Image Types.

Return Value

A composite image formed from the contents of the specified set of windows. If the windows are unreadable or no windows meet the specified criteria, this function returns an image that is either 0 by 0 pixels in size or is of the specified size but is filled with the transparent black color. If you call this function from outside of a GUI security session or when no window server is running, this function returns NULL.


Any windows that are onscreen but whose sharing setting is set to CGWindowSharingType.none are skipped and not included in the resulting image. If this results in no windows being available in the selected range, this function returns NULL.

See Also

Getting Window Information

func CGWindowListCopyWindowInfo(CGWindowListOption, CGWindowID) -> CFArray?

Generates and returns information about the selected windows in the current user session.

func CGWindowListCreateDescriptionFromArray(CFArray?) -> CFArray?

Generates and returns information about windows with the specified window IDs.