Skip to content

Instantly share code, notes, and snippets.

@zappycode
Last active June 12, 2024 02:15
Show Gist options
  • Select an option

  • Save zappycode/3b5e151d4d98407901af5748745f5845 to your computer and use it in GitHub Desktop.

Select an option

Save zappycode/3b5e151d4d98407901af5748745f5845 to your computer and use it in GitHub Desktop.

Revisions

  1. zappycode revised this gist Jul 20, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions NSImageToJpeg.swift
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    func jpegDataFrom(image:NSImage) -> Data {
    let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
    let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
    let jpegData = bitmapRep.representation(using: NSBitmapImageFileType.JPEG, properties: [:])!
    return jpegData
    }
    let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
    let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
    let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
    return jpegData
    }
  2. zappycode created this gist Mar 30, 2017.
    6 changes: 6 additions & 0 deletions NSImageToJpeg.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    func jpegDataFrom(image:NSImage) -> Data {
    let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
    let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
    let jpegData = bitmapRep.representation(using: NSBitmapImageFileType.JPEG, properties: [:])!
    return jpegData
    }