NSImage

Extends NSImage to support the Action Data controls and adds convenience methods for working with image properties in a Codable, Encodable or Decodable class.

Examples:

// Assign aa image from Base 64 encoded String in macOS
let imageString = NSImage(named: "Background.png").toString()
let image: NSImage ~= imageString
  • Returns the image as data in the png format.

    Example:

    // Get png Data from image
    let data = NSImage(named: "Background.png").pngData
    

    Declaration

    Swift

    public var pngData: Data?
  • Returns the image as data in the jpeg format.

    Example:

    // Get jpeg Data from image
    let data = NSImage(named: "Background.png").jpgData
    

    Declaration

    Swift

    public var jpgData: Data?
  • Defines the Image Representation Format that will be used when converting a NSImage to String (via toString()) or to Data (via toData()).

    See more

    Declaration

    Swift

    public enum ImageRepresentationFormat
  • Sets the NSImage from the given String Instance.

    Examples:

    // Assign an image from Base 64 encoded String in macOS
    let imageString = NSImage(named: "Background.png").toString()
    let image: NSImage ~= imageString
    

    Declaration

    Swift

    public static func ~= ( left: inout NSImage, right: String)
  • Sets the NSImage from the given Data instance.

    Examples:

    // Assign an image from Base 64 encoded Data in macOS
    let imageData = NSImage(named: "Background.png").toData()
    let image: NSImage ~= imageData
    

    Declaration

    Swift

    public static func ~= ( left: inout NSImage, right: Data)
  • Converts the NSImage to a String representation encoded in Base 64.

    Examples:

    // Assign an image to Base 64 encoded String in macOS
    let imageString = NSImage(named: "Background.png").toString()
    

    Declaration

    Swift

    public func toString(imageRepresentation: ImageRepresentationFormat = .pngRepresentation) -> String

    Parameters

    imageRepresentation

    Determines the representation that will be used when converting the image. The default is pngRepresentation.

    Return Value

    The NSImage in the requested representation converted to a Base 64 encoded string.

  • Converst the NSImage to a Data representation.

    Examples:

    // Assign an image to Base 64 encoded Data in macOS
    let imageData = NSImage(named: "Background.png").toString()
    

    Declaration

    Swift

    public func toData(imageRepresentation: ImageRepresentationFormat = .pngRepresentation) -> Data?

    Parameters

    imageRepresentation

    Determins the representation that will be used when converting the image. The default is pngRepresentation.

    Return Value

    The NSImage in the requested representation converted to a raw Data.

  • Creates a new NSImage instance from a Base 64 encoded string.

    Examples:

    // Assign an image from Base 64 encoded String in macOS
    let imageString = NSImage(named: "Background.png").toString()
    let image = NSImage(fromString: imageString)
    

    Declaration

    Swift

    public convenience init?(fromString value: String)

    Parameters

    value

    A Base 64 encoded String representing an image.

  • Creates a new NSImage instance from a string specifying the name of an image added as an asset.

    Examples:

    // Assign an image from an asset name in macOS
    let imageString = NSImage(named: "Background.png")
    

    Declaration

    Swift

    public convenience init?(named: String)

    Parameters

    value

    A Base 64 encoded String representing an image.