The NSBitmapImageRep class renders an image from bitmap data. Supported bitmap data formats include GIF, JPEG, TIFF, PNG, and various permutations of raw bitmap data.


Alpha Premultiplication and Bitmap Formats

When creating a bitmap using a premultiplied format, if a coverage (alpha) plane exists, the bitmap’s color components are premultiplied with it. In this case, if you modify the contents of the bitmap, you are therefore responsible for premultiplying the data. Note that premultiplying generally has negligible effect on output quality. For floating-point image data, premultiplying color components is a lossless operation, but for fixed-point image data, premultiplication can introduce small rounding errors. In either case, more rounding errors may appear when compositing many premultiplied images; however, such errors are generally not readily visible.

For this reason, you should not use an NSBitmapImageRep object if you want to manipulate image data. To work with data that is not premultiplied, use the Core Graphics framework instead. (Specifically, create images using the init(width:height:bitsPerComponent:bitsPerPixel:bytesPerRow:space:bitmapInfo:provider:decode:shouldInterpolate:intent:) function and last parameter.) Alternatively, include the NSAlphaNonpremultipliedBitmapFormat flag when creating the bitmap.


Creating an NSBitmapImageRep Object

class func imageReps(with: Data)

Creates and returns an array of initialized NSBitmapImageRep objects corresponding to the images in the supplied data.

init(cgImage: CGImage)

Returns an NSBitmapImageRep object created from a Core Graphics image object.

init(ciImage: CIImage)

Returns an NSBitmapImageRep object created from a Core Image object.

init?(data: Data)

Initializes a newly allocated NSBitmapImageRep from the provided data.

init?(focusedViewRect: NSRect)

Initializes the receiver, a newly allocated NSBitmapImageRep object, with bitmap data read from a rendered image.

init(forIncrementalLoad: ())

Initializes and returns the receiver, a newly allocated NSBitmapImageRep object, for incremental loading.

Getting Information About the Image

var bitmapFormat: NSBitmapFormat

The format of the bitmap image representation.

var bitsPerPixel: Int

The number of bits allocated for each pixel in each plane of data.

var bytesPerPlane: Int

The number of bytes in each plane or channel of data.

var bytesPerRow: Int

The minimum number of bytes required to specify a scan line in each data plane.

var isPlanar: Bool

A Boolean value indicating whether the image data is in a planar configuration.

var numberOfPlanes: Int

The number of separate planes into which the image data is organized.

var samplesPerPixel: Int

The number of components for each pixel.

Getting Image Data

func getBitmapDataPlanes(UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>)

Returns by indirection bitmap data of the receiver separated into planes.

Producing Representations of the Image

class func tiffRepresentationOfImageReps(in: [NSImageRep])

Returns a TIFF representation of the given images

class func tiffRepresentationOfImageReps(in: [NSImageRep], using: NSTIFFCompression, factor: Float)

Returns a TIFF representation of the given images using a specified compression scheme and factor.

var tiffRepresentation: Data?

A TIFF representation of the bitmap image data.

func tiffRepresentation(using: NSTIFFCompression, factor: Float)

Returns a TIFF representation of the image using the specified compression.

class func representationOfImageReps(in: [NSImageRep], using: NSBitmapImageFileType, properties: [String : Any])

Formats the specified bitmap images using the specified storage type and properties and returns them in a data object.

func representation(using: NSBitmapImageFileType, properties: [String : Any])

Formats the receiver’s image data using the specified storage type and properties and returns it in a data object.

Managing Compression Types

class func getTIFFCompressionTypes(UnsafeMutablePointer<UnsafePointer<NSTIFFCompression>?>, count: UnsafeMutablePointer<Int>)

Returns by indirection an array of all available compression types that can be used when writing a TIFF image.

class func localizedName(forTIFFCompressionType: NSTIFFCompression)

Returns an autoreleased string containing the localized name for the specified compression type.

func canBeCompressed(using: NSTIFFCompression)

Tests whether the receiver can be compressed by the specified compression scheme.

func setCompression(NSTIFFCompression, factor: Float)

Sets the receiver’s compression type and compression factor.

func getCompression(UnsafeMutablePointer<NSTIFFCompression>?, factor: UnsafeMutablePointer<Float>?)

Returns by indirection the receiver’s compression type and compression factor.

func setProperty(String, withValue: Any?)

Sets the image’s property to value.

func value(forProperty: String)

Returns the value for the specified property.

Loading Image Incrementally

func incrementalLoad(from: Data, complete: Bool)

Loads the current image data into an incrementally-loaded image representation and returns the current status of the image.

Managing Pixel Values

func setColor(NSColor, atX: Int, y: Int)

Changes the color of the pixel at the specified coordinates.

func colorAt(x: Int, y: Int)

Returns the color of the pixel at the specified coordinates.

func setPixel(UnsafeMutablePointer<Int>!, atX: Int, y: Int)

Sets the receiver's pixel at the specified coordinates to the specified raw pixel values.

func getPixel(UnsafeMutablePointer<Int>!, atX: Int, y: Int)

Returns by indirection the pixel data for the specified location in the receiver.

Getting a Core Graphics Image

var cgImage: CGImage?

A Core Graphics image object based on the bitmap image rep’s data.

Managing ColorSpaces

func converting(to: NSColorSpace, renderingIntent: NSColorRenderingIntent)

Converts the image rep to the specified colorspace

func retagging(with: NSColorSpace)

Changes the colorSpace tag of the receiver.

var colorSpace: NSColorSpace

The color space of the bitmap.



Constants representing the various status values returned by incrementalLoad(from:complete:).


Constants for specifying the bitmap file types.


Constants representing the supported TIFF data-compression schemes.


Constants representing the various bitmap component formats.


Inherits From

Conforms To