Skip to content

Instantly share code, notes, and snippets.

@cbess
Last active November 22, 2018 15:51

Revisions

  1. cbess revised this gist Nov 22, 2018. No changes.
  2. cbess revised this gist Nov 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NSView+Screenshot.m
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ @implementation NSView (Screenshot)

    /// Returns an image that contains the entire window contents, including window background color and traffic lights.
    /// Resembles the product of taking a screenshot using Preview.app
    - (NSImage *)screenshotFromDisplay {
    - (NSImage *)screenshotOfWindow {
    CGWindowID winID = (CGWindowID) self.window.windowNumber;
    CGImageRef ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winID, kCGWindowImageBoundsIgnoreFraming);
    return [[NSImage alloc] initWithCGImage:ref size:self.bounds.size];
  3. cbess renamed this gist Nov 22, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. cbess created this gist Nov 22, 2018.
    13 changes: 13 additions & 0 deletions screenshot.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // ref: https://stackoverflow.com/a/22967912/344591

    @implementation NSView (Screenshot)

    /// Returns an image that contains the entire window contents, including window background color and traffic lights.
    /// Resembles the product of taking a screenshot using Preview.app
    - (NSImage *)screenshotFromDisplay {
    CGWindowID winID = (CGWindowID) self.window.windowNumber;
    CGImageRef ref = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winID, kCGWindowImageBoundsIgnoreFraming);
    return [[NSImage alloc] initWithCGImage:ref size:self.bounds.size];
    }

    @end