Mac Developer Library

Developer

AppKit Framework Reference NSImageRep Class Reference

Options
Deployment Target:

On This Page
Language:

NSImageRep

The NSImageRep class is a semiabstract superclass (“semi” because it has some instance variables and implementation of its own). Each of its subclasses knows how to draw an image from a particular kind of source data. While an NSImageRep subclass can be used directly, it is typically through an NSImage object. An NSImage object manages a group of image representations, choosing the best one for the current output device.

Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.0 and later.
  • Creates and returns an array of image representation objects initialized using the contents of the specified file.

    Declaration

    Swift

    class func imageRepsWithContentsOfFile(_ filename: String) -> [AnyObject]?

    Objective-C

    + (NSArray *)imageRepsWithContentsOfFile:(NSString *)filename

    Parameters

    filename

    A full or relative pathname specifying the file to open. This string should include the filename extension.

    Return Value

    An array of image representation objects. The array contains one object for each image in the specified file.

    Discussion

    If sent to the NSImageRep class object, this method returns an array of objects (all newly allocated instances of a subclass of NSImageRep, chosen through the use of imageRepClassForFileType:) that have been initialized with the contents of the file. If sent to a subclass of NSImageRep that recognizes the file type, this method returns an array of objects (all instances of that subclass) that have been initialized with the contents of the file.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle the data in the file.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle the data in the file.

    • The NSImageRep subclass is unable to initialize itself with the contents of filename.

    The NSImageRep subclass is initialized by creating an NSData object based on the contents of the file and passing it to the imageRepsWithData: method of the subclass. By default, the files handled include those with the extensions “tiff”, “gif”, “jpg”, “pict”, “pdf”, and “eps”.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an array of image representation objects initialized using the contents of the pasteboard.

    Declaration

    Swift

    class func imageRepsWithPasteboard(_ pasteboard: NSPasteboard) -> [AnyObject]?

    Objective-C

    + (NSArray *)imageRepsWithPasteboard:(NSPasteboard *)pasteboard

    Parameters

    pasteboard

    The pasteboard containing the image data.

    Return Value

    An array of image representation objects. The array contains one object for each image in the specified pasteboard.

    Discussion

    If sent to the NSImageRep class object, this method returns an array of objects (all newly-allocated instances of a subclass of NSImageRep) that have been initialized with the data in the specified pasteboard. If sent to a subclass of NSImageRep that recognizes the pasteboard data, it returns an array of objects (all instances of that subclass) initialized with the pasteboard data.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle the pasteboard data.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle the pasteboard data.

    • The NSImageRep subclass is unable to initialize itself with the contents the pasteboard.

    The NSImageRep subclass is initialized by creating an NSData object based on the data in pasteboard and passing it to the imageRepsWithData: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an array of image representation objects initialized using the contents of the specified URL.

    Declaration

    Swift

    class func imageRepsWithContentsOfURL(_ aURL: NSURL) -> [AnyObject]?

    Objective-C

    + (NSArray *)imageRepsWithContentsOfURL:(NSURL *)aURL

    Parameters

    aURL

    The URL pointing to the image data.

    Return Value

    An array of image representation objects. The array contains one object for each image in the data at the specified URL.

    Discussion

    If sent to the NSImageRep class object, this method returns an array of objects (all newly allocated instances of a subclass of NSImageRep) that have been initialized with the contents of the specified URL. If sent to a subclass of NSImageRep that recognizes the data at the specified URL, it returns an array of objects (all instances of that subclass) that have been initialized with the contents of that URL.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle data in the specified URL.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle data in the specified URL.

    • The NSImageRep subclass is unable to initialize itself with the contents of the specified URL.

    The NSImageRep subclass is initialized by creating an NSData object based on the contents of the specified URL and passing it to the imageRepsWithData: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an image representation object using the contents of the specified file.

    Declaration

    Swift

    class func imageRepWithContentsOfFile(_ filename: String) -> AnyObject?

    Objective-C

    + (id)imageRepWithContentsOfFile:(NSString *)filename

    Parameters

    filename

    A full or relative pathname specifying the file to open. This string should include the filename extension.

    Return Value

    An initialized instance of an NSImageRep subclass, or nil if the image data could not be read.

    Discussion

    If sent to the NSImageRep class object, this method returns a newly allocated instance of a subclass of NSImageRep (chosen through the use of imageRepClassForFileType:) initialized with the contents of the specified file. If sent to a subclass of NSImageRep that recognizes the type of data in the file, it returns an instance of that subclass initialized with the contents of the file.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle the type of data in the specified file.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle the type of data in the specified file.

    • The NSImageRep subclass is unable to initialize itself with the contents of the specified file.

    The NSImageRep subclass is initialized by creating an NSData object based on the contents of the file and passing it to the imageRepWithData: method. By default, the files handled include those with the extensions “tiff”, “gif”, “jpg”, “pict”, “pdf”, and “eps”.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an image representation object using the contents of the specified pasteboard.

    Declaration

    Swift

    class func imageRepWithPasteboard(_ pasteboard: NSPasteboard) -> AnyObject?

    Objective-C

    + (id)imageRepWithPasteboard:(NSPasteboard *)pasteboard

    Parameters

    pasteboard

    The pasteboard containing the image data.

    Return Value

    An initialized instance of an NSImageRep subclass, or nil if the image data could not be read.

    Discussion

    If sent to the NSImageRep class object, this method returns a newly allocated instance of a subclass of NSImageRep initialized with the data in the specified pasteboard. If sent to a subclass of NSImageRep that recognizes the data on the pasteboard, it returns an instance of that subclass initialized with that data.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle data of the type contained in the specified pasteboard.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle data of the type contained in the specified pasteboard.

    • The NSImageRep subclass is unable to initialize itself with the contents of the pasteboard.

    The NSImageRep subclass is initialized by creating an NSData object based on the data the specified pasteboard and passing it to the imageRepWithData: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and returns an image representation object using the data at the specified URL

    Declaration

    Swift

    class func imageRepWithContentsOfURL(_ aURL: NSURL) -> AnyObject?

    Objective-C

    + (id)imageRepWithContentsOfURL:(NSURL *)aURL

    Parameters

    aURL

    The URL pointing to the image data.

    Return Value

    An initialized instance of an NSImageRep subclass, or nil if the image data could not be read.

    Discussion

    If sent to the NSImageRep class object, this method returns a newly allocated instance of a subclass of NSImageRep initialized with the contents of the specified URL. If sent to a subclass of NSImageRep that recognizes the data contained in the URL, it returns an instance of that subclass initialized with the data in the URL.

    This method returns nil in any of the following cases:

    • The message is sent to the NSImageRep class object and there are no subclasses in the NSImageRep class registry that handle the data contained in the specified URL.

    • The message is sent to a subclass of NSImageRep and that subclass cannot handle the data contained in the specified URL.

    • The NSImageRep subclass is unable to initialize itself with the contents of the specified URL.

    The NSImageRep subclass is initialized by creating an NSData object based on the contents of the file, then passing it to the imageRepWithData: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether the receiver can initialize itself from the specified data.

    Declaration

    Swift

    class func canInitWithData(_ data: NSData) -> Bool

    Objective-C

    + (BOOL)canInitWithData:(NSData *)data

    Parameters

    data

    The image data.

    Return Value

    YEStrue if the receiver understands the format of the specified data and can use it to initialize itself; otherwise, NOfalse.

    Discussion

    This method should be overridden by subclasses. Note that this method does not need to do a comprehensive check of the image data; it should return NOfalse only if it knows it cannot initialize itself from the data.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value indicating whether the receiver can initialize itself from the data on the specified pasteboard.

    Declaration

    Swift

    class func canInitWithPasteboard(_ pasteboard: NSPasteboard) -> Bool

    Objective-C

    + (BOOL)canInitWithPasteboard:(NSPasteboard *)pasteboard

    Parameters

    pasteboard

    The pasteboard containing the image data.

    Return Value

    YEStrue if the receiver understands the format of the specified data and can use it to initialize itself; otherwise, NOfalse.

    Discussion

    This method invokes the imageUnfilteredPasteboardTypes class method and checks the list of types returned by that method against the data types in pasteboard. If it finds a match, it returns YEStrue. When creating a subclass of NSImageRep that accepts image data from a non-default pasteboard type, override the imageUnfilteredPasteboardTypes method to assure this method returns the correct response.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an array of UTI strings identifying the image types supported by the receiver, either directly or through a user-installed filter service.

    Declaration

    Swift

    class func imageTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imageTypes

    Return Value

    An array of NSString objects, each of which contains a UTI identifying a supported image type. Some sample image-related UTI strings include "public.image”, "public.jpeg”, and "public.tiff”. For a list of supported types, see UTCoreTypes.h.

    Discussion

    The returned list includes UTIs all file types supported by this image representation object plus those that can be opened by this image representation after being converted by a user-installed filter service. You can use the returned UTI strings with any method that supports UTIs.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns an array of UTI strings identifying the image types supported directly by the receiver.

    Declaration

    Swift

    class func imageUnfilteredTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imageUnfilteredTypes

    Return Value

    An array of NSString objects, each of which contains a UTI identifying a supported image type. Some sample image-related UTI strings include "public.image”, "public.jpeg”, and "public.tiff”. For a list of supported types, see UTCoreTypes.h.

    Discussion

    The returned list includes UTI strings only for those file types that are supported directly by the receiver. It does not include types that are supported through user-installed filter services. You can use the returned UTI strings with any method that supports UTIs.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the file types supported by NSImageRep or one of its subclasses.

    Declaration

    Swift

    class func imageFileTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imageFileTypes

    Return Value

    An array of NSString objects, each of which contains a filename extension or HFS file type of a supported format.

    Discussion

    The list includes both those types returned by the imageUnfilteredFileTypes class method plus those that can be converted to a supported type by a user-installed filter service. The returned file types can include encoded HFS file types as well as filename extensions.

    Don’t override this method when subclassing NSImageRep—it always returns a valid list for any subclass of NSImageRep that correctly overrides the imageUnfilteredFileTypes method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the pasteboard types supported by NSImageRep or one of its subclasses.

    Declaration

    Swift

    class func imagePasteboardTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imagePasteboardTypes

    Return Value

    An array of NSString objects, each of which contains a supported pasteboard format.

    Discussion

    The list includes both those types returned by the imageUnfilteredPasteboardTypes class method plus those that can be converted to a supported type by a user-installed filter service. Don’t override this method when subclassing NSImageRep—it always returns a valid list for any subclass of NSImageRep that correctly overrides the imageUnfilteredPasteboardTypes method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the list of file types supported directly by the receiver.

    Declaration

    Swift

    class func imageUnfilteredFileTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imageUnfilteredFileTypes

    Return Value

    An array of NSString objects. This array is empty by default. Subclasses must override to return the list of file formats they support.

    Discussion

    The returned file types can include encoded HFS file types as well as filename extensions. When creating a subclass of NSImageRep, override this method to return a list of strings representing the supported file types. For example, the NSBitmapImageRep class implements code similar to the following for this method:

    • + (NSArray *)imageUnfilteredFileTypes {
    • static NSArray *types = nil;
    • if (!types) types = [[NSArray alloc]
    • initWithObjects:@"tiff", @"gif", @"jpg", @"bmp", nil];
    • return types;
    • }

    If your subclass supports the types supported by its superclass, you must explicitly get the array of types from the superclass and put them in the array returned by this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the list of pasteboard types supported directly by the receiver.

    Declaration

    Swift

    class func imageUnfilteredPasteboardTypes() -> [AnyObject]

    Objective-C

    + (NSArray *)imageUnfilteredPasteboardTypes

    Return Value

    An array of NSString objects. This array is empty by default. Subclasses must override to return the list of pasteboard formats they support.

    Discussion

    When creating a subclass of NSImageRep, override this method to return a list representing the supported pasteboard types. For example, the NSBitmapImageRep class implements code similar to the following for this method:

    • + (NSArray *)imageUnfilteredPasteboardTypes {
    • static NSArray *types = nil;
    • if (!types) types = [[NSArray alloc] initWithObjects:NSTIFFPboardType, nil];
    • return types;
    • }

    If your subclass supports the types supported by its superclass, you must explicitly get the list of types from the superclass and add them to the array returned by this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the size of the image representation to the specified value.

    Declaration

    Swift

    var size: NSSize

    Objective-C

    @property NSSize size

    Parameters

    aSize

    The new size of the image representation, measured in points in the user coordinate space.

    Discussion

    This method determines the size of the image when it’s rendered. It is not necessarily the same as the width and height of the image in pixels as specified by the image data, nor must it be equal to the size set for the NSImage object that wraps this image representation. You must set the image size before you can render it.

    The size of an image representation combined with the physical dimensions of the image data determine the resolution of the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the image representation.

    Declaration

    Swift

    var size: NSSize

    Objective-C

    @property NSSize size

    Return Value

    The size of the image representation, measured in points in the user coordinate space.

    Discussion

    This size is the size of the image representation when it’s rendered. It is not necessarily the same as the width and height of the image in pixels as specified by the image data, nor must it be equal to the size set for the NSImage object that wraps this image representation.

    The size of an image representation combined with the physical dimensions of the image data determine the resolution of the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the number of bits per sample in the receiver.

    Declaration

    Swift

    var bitsPerSample: Int

    Objective-C

    @property NSInteger bitsPerSample

    Return Value

    The number of bits used to specify each component of data in a single pixel (for example, a value of 8 for an RGBA image means that each pixel is comprised of four 8-bit values). May also return NSImageRepMatchesDevice.

    Discussion

    If the receiver is a planar image, this method returns the number of bits per sample per plane.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setBitsPerSample:
    – bitsPerPixel (NSBitmapImageRep)
    – samplesPerPixel (NSBitmapImageRep)
    – isPlanar (NSBitmapImageRep)

  • Returns the name of the receiver's color space.

    Declaration

    Swift

    var colorSpaceName: String

    Objective-C

    @property(copy) NSString *colorSpaceName

    Return Value

    The colorspace name, or NSCalibratedRGBColorSpace if no name has been assigned.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • hasAlpha hasAlpha Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value indicating whether the receiver has an alpha channel.

    Declaration

    Objective-C

    - (BOOL)hasAlpha

    Return Value

    YEStrue if the receiver has a known alpha channel; otherwise, NOfalse.

    Import Statement

    Availability

    Available in OS X v10.0 through OS X v10.9.

    See Also

    – setAlpha:

  • isOpaque isOpaque Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value indicating whether the receiver is opaque.

    Declaration

    Objective-C

    - (BOOL)isOpaque

    Return Value

    YEStrue if the receiver is opaque; otherwise, NOfalse.

    Discussion

    Use this method to test whether an image representation completely covers the area within the rectangle returned by the size method.

    The returned value does not indicate whether the image has an alpha channel or if there is partial or complete transparency when drawing the image rep. Use the hasAlpha method to determine if the image has an alpha channel.

    Import Statement

    Availability

    Available in OS X v10.0 through OS X v10.9.

    See Also

    – setOpaque:

  • Returns the height of the image, measured in pixels.

    Declaration

    Swift

    var pixelsHigh: Int

    Objective-C

    @property NSInteger pixelsHigh

    Return Value

    The height of the image, measured in the units of the device coordinate space. This value is usually derived from the image data itself.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the width of the image, measured in pixels.

    Declaration

    Swift

    var pixelsWide: Int

    Objective-C

    @property NSInteger pixelsWide

    Return Value

    The width of the image, measured in the units of the device coordinate space. This value is usually derived from the image data itself.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Informs the receiver that its image data has an alpha component.

    Declaration

    Swift

    var alpha: Bool

    Objective-C

    @property(getter=hasAlpha) BOOL alpha

    Parameters

    flag

    YEStrue if you want the receiver to have an alpha component; otherwise NOfalse.

    Discussion

    Subclasses should call this method when loading image data to notify the parent class whether that data contains an alpha component. Passing in a value of YEStrue does not add an alpha channel to the image data itself; it merely records the fact that the data has an alpha channel.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – hasAlpha

  • Informs the receiver that its image data has the specified number of bits for each component of a pixel.

    Declaration

    Swift

    var bitsPerSample: Int

    Objective-C

    @property NSInteger bitsPerSample

    Parameters

    anInt

    The number of bits used by each component of a pixel, or NSImageRepMatchesDevice.

    Discussion

    Subclasses should call this method when loading image data to notify the parent class of how many bits each sample uses. Specifying a value that differs from the actual image data does not change the bit depth of the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Informs the receiver of the color space used by the image data.

    Declaration

    Swift

    var colorSpaceName: String

    Objective-C

    @property(copy) NSString *colorSpaceName

    Parameters

    string

    The name of the color space used by the image data.

    Discussion

    By default, an NSImageRep object’s color space name is NSCalibratedRGBColorSpace. Color space names are defined as part of the NSColor class, in NSGraphics.h. The following are valid color space names:

    • NSCalibratedWhiteColorSpace

    • NSCalibratedBlackColorSpace

    • NSCalibratedRGBColorSpace

    • NSDeviceWhiteColorSpace

    • NSDeviceBlackColorSpace

    • NSDeviceRGBColorSpace

    • NSDeviceCMYKColorSpace

    • NSNamedColorSpace

    • NSCustomColorSpace

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets whether the receiver's image is opaque.

    Declaration

    Swift

    var opaque: Bool

    Objective-C

    @property(getter=isOpaque) BOOL opaque

    Parameters

    flag

    YEStrue if the image should be treated as fully opaque; otherwise, NOfalse to indicate the image may include some transparent regions.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – isOpaque

  • Informs the receiver of the image data height.

    Declaration

    Swift

    var pixelsHigh: Int

    Objective-C

    @property NSInteger pixelsHigh

    Parameters

    anInt

    The height of the image, measured in pixels.

    Discussion

    Subclasses should call this method when loading image data to notify the parent class of the image height. You cannot use this method to change the actual number of pixels in the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Informs the receiver of the image data width.

    Declaration

    Swift

    var pixelsWide: Int

    Objective-C

    @property NSInteger pixelsWide

    Parameters

    anInt

    The width of the image, measured in pixels.

    Discussion

    Subclasses should call this method when loading image data to notify the parent class of the image width. You cannot use this method to change the actual number of pixels in the image.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a CGImage capturing the drawing of the receiver.

    Declaration

    Swift

    func CGImageForProposedRect(_ proposedDestRect: UnsafeMutablePointer<NSRect>, context context: NSGraphicsContext?, hints hints: [NSObject : AnyObject]?) -> Unmanaged<CGImage>?

    Objective-C

    - (CGImageRef)CGImageForProposedRect:(NSRect *)proposedDestRect context:(NSGraphicsContext *)context hints:(NSDictionary *)hints

    Parameters

    proposedDestRect

    On input, the proposed destination rectangle for drawing the image. If NULL, it defaults to the smallest pixel-integral rectangle containing {{0,0}, [self size]}. The proposedDestRect is in user space in the reference context.

    On output the proposedDestRect may have been altered. This is because a CGImage is necessarily pixel-integral, while an NSImage is not. In order to produce a CGImage for rect (0.5, 0.5, 4.0, 4.0) without distortion or double-antialiasing, we may have to produce a 5x5 CGImage, and also inflate the proposedDestRect. Drawing the CGImage in the out-value proposedDestRect is the same as drawing the NSImage in the in-value of proposed rect.

    context

    A graphics context., Can be NULL.

    hints

    An optional dictionary of hints that provide more context for selecting or generating the image. See Image_Hint_Dictionary_Keys for a summary of the possible key-value pairs.

    Return Value

    A CGImageRef. This may be an existing CGImage if one is available. If not, a new CGImage is created.

    Discussion

    An NSImage is potentially resolution independent, and may have representations that allow it to draw well in many contexts. A CGImage is more like a single pixel-based representation. This method produces a snapshot of how the NSImage would draw if it was asked to draw in the proposed rectangle in the graphics context.

    All input parameters are optional. They provide hints for how to choose among existing CGImages, or how to create one if there isn't already a CGImage available. The parameters are only hints.

    This method is intended as an override point for image rep subclasses that naturally have a CGImage available. For example, NSBitmapImageRep overrides it to return the CGImage that naturally backs the rep. You don't need to override the method except possibly for performance, though. The NSImageRep-level implementation will produce a CGImage by making a buffer and calling [self draw]. That's likely to be the best possible implementation for reps that aren't naturally CGImage backed. The draw remains the only method of NSImageRep that a subclasser really needs to override.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Implemented by subclasses to draw the image in the current coordinate system.

    Declaration

    Swift

    func draw() -> Bool

    Objective-C

    - (BOOL)draw

    Return Value

    YEStrue if the image was successfully drawn; otherwise, NOfalse if there was a problem. The default version of this method simply returns YEStrue.

    Discussion

    Subclass override this method to draw the image using the image data. By the time this method is called, the graphics state is already configured for you to draw the image at location (0.0, 0.0) in the current coordinate system.

    The standard Application Kit subclasses all draw the image using the NSCompositeCopy composite operation defined in the Constants section of NSImage. Using the copy operator, the image data overwrites the destination without any blending effects. Transparent (alpha) regions in the source image appear black. To use other composite operations, you must place the representation into an NSImage object and use its drawAtPoint:fromRect:operation:fraction: or drawInRect:fromRect:operation:fraction: methods.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the receiver's image data at the specified point in the current coordinate system.

    Declaration

    Swift

    func drawAtPoint(_ aPoint: NSPoint) -> Bool

    Objective-C

    - (BOOL)drawAtPoint:(NSPoint)aPoint

    Parameters

    aPoint

    The point in the current coordinate system at which to draw the image.

    Return Value

    YEStrue if the image was successfully drawn; otherwise, NOfalse. If the size of the image has not yet been set, this method returns NOfalse immediately

    Discussion

    This method sets the origin of the current coordinate system to the specified point and then invokes the receiver’s draw method to draw the image at that point. Upon completion, it restores the current coordinates to their original setting. If aPoint is (0.0, 0.0), this method simply invokes the draw method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws the image, scaling it (as needed) to fit the specified rectangle.

    Declaration

    Swift

    func drawInRect(_ rect: NSRect) -> Bool

    Objective-C

    - (BOOL)drawInRect:(NSRect)rect

    Parameters

    rect

    The rectangle in the current coordinate system in which to draw the image.

    Return Value

    YEStrue if the image was successfully drawn; otherwise, NOfalse. If the size of the image has not yet been set, this method returns NOfalse immediately

    Discussion

    This method sets the origin of the current coordinate system to the origin of the specified rectangle before invoking the receiver's draw method. If the rectangle size is different from the image's native size, this method adjusts the coordinate transform, causing the image to be scaled appropriately. After the draw method returns, the coordinate system changes are undone, restoring the original graphics state.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Draws all or part of the image in the specified rectangle in the current coordinate system.

    Declaration

    Swift

    func drawInRect(_ dstSpacePortionRect: NSRect, fromRect srcSpacePortionRect: NSRect, operation op: NSCompositingOperation, fraction requestedAlpha: CGFloat, respectFlipped respectContextIsFlipped: Bool, hints hints: [NSObject : AnyObject]?) -> Bool

    Objective-C

    - (BOOL)drawInRect:(NSRect)dstSpacePortionRect fromRect:(NSRect)srcSpacePortionRect operation:(NSCompositingOperation)op fraction:(CGFloat)requestedAlpha respectFlipped:(BOOL)respectContextIsFlipped hints:(NSDictionary *)hints

    Parameters

    dstSpacePortionRect

    The rectangle in which to draw the image, specified in the current coordinate system.

    srcSpacePortionRect

    The source rectangle specifying the portion of the image you want to draw. The coordinates of this rectangle must be specified using the image's own coordinate system. If you pass in NSZeroRect, the entire image is drawn.

    op

    The compositing operation to use when drawing the image. See the NSCompositingOperation constants.

    requestedAlpha

    The opacity of the image, specified as a value from 0.0 to 1.0. Specifying a value of 0.0 draws the image as fully transparent while a value of 1.0 draws the image as fully opaque. Values greater than 1.0 are interpreted as 1.0.

    respectContextIsFlipped

    YEStrue if the flipped context of the receiver should be respected, otherwise NOfalse.

    hints

    An optional dictionary of hints that provide more context for selecting or generating the image. See Image_Hint_Dictionary_Keys for a summary of the possible key-value pairs.

    Return Value

    YEStrue if the image was successfully drawn; otherwise, NOfalse.

    Discussion

    If the srcSpacePortionRect and dstSpacePortionRect rectangles have different sizes, the source portion of the image is scaled to fit the specified destination rectangle.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the NSImageRep subclass that handles image data for the specified UTI.

    Declaration

    Swift

    class func imageRepClassForType(_ type: String) -> AnyClass?

    Objective-C

    + (Class)imageRepClassForType:(NSString *)type

    Parameters

    type

    The UTI string identifying the desired image type. Some sample image-related UTI strings include "public.image”, "public.jpeg”, and "public.tiff”. For a list of supported types, see UTCoreTypes.h.

    Return Value

    A Class object for the image representation that can handle the UTI, or nil if no image representation could handle the data.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the NSImageRep subclass that handles the specified type of data.

    Declaration

    Swift

    class func imageRepClassForData(_ data: NSData) -> AnyClass?

    Objective-C

    + (Class)imageRepClassForData:(NSData *)data

    Parameters

    data

    The image data.

    Return Value

    A Class object for the image representation that can handle the data, or nil if no image representation could handle the data.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the NSImageRep subclass that handles data with the specified type.

    Declaration

    Swift

    class func imageRepClassForFileType(_ type: String) -> AnyClass?

    Objective-C

    + (Class)imageRepClassForFileType:(NSString *)type

    Parameters

    type

    A string containing the filename extension or an encoded HFS type.

    Return Value

    A Class object for the image representation that can handle the type of data, or nil if no image representation could handle the type.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the NSImageRep subclass that handles data with the specified pasteboard type.

    Declaration

    Swift

    class func imageRepClassForPasteboardType(_ type: String) -> AnyClass?

    Objective-C

    + (Class)imageRepClassForPasteboardType:(NSString *)type

    Parameters

    type

    The pasteboard type.

    Return Value

    A Class object for the image representation that can handle the specified pasteboard type, or nil if no image representation could handle the type.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns an array containing the registered NSImageRep classes.

    Declaration

    Swift

    class func registeredImageRepClasses() -> [AnyObject]

    Objective-C

    + (NSArray *)registeredImageRepClasses

    Return Value

    An array of Class objects identifying the registered NSImageRep subclasses.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Adds the specified class to the registry of available NSImageRep subclasses.

    Declaration

    Swift

    class func registerImageRepClass(_ imageRepClass: AnyClass)

    Objective-C

    + (void)registerImageRepClass:(Class)imageRepClass

    Parameters

    imageRepClass

    The Class object for an NSImageRep subclass.

    Discussion

    This method posts an NSImageRepRegistryDidChangeNotification, along with the receiving object, to the default notification center.

    A good place to add image representation classes to the registry is in the load class method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    + unregisterImageRepClass:
    load (NSObject)

  • Removes the specified NSImageRep subclass from the registry of available image representations.

    Declaration

    Swift

    class func unregisterImageRepClass(_ imageRepClass: AnyClass)

    Objective-C

    + (void)unregisterImageRepClass:(Class)imageRepClass

    Parameters

    imageRepClass

    The Class object for an NSImageRep subclass.

    Discussion

    This method posts the NSImageRepRegistryDidChangeNotification, along with the receiving object, to the default notification center.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The following constant is used by NSImageRep to denote an attribute whose value changes to match the display device.

    Declaration

    Swift

    var NSImageRepMatchesDevice: Int { get }

    Objective-C

    enum { NSImageRepMatchesDevice };

    Constants

    • NSImageRepMatchesDevice

      NSImageRepMatchesDevice

      Indicates that the value of certain attributes, such as the number of colors or bits per sample, will change to match the display device.

      This value can be passed in (or received back) as the value of bitsPerSample, pixelsWide, and pixelsHigh.

      Available in OS X v10.0 and later.

    Import Statement

  • The following constant maps to the new notification and is for legacy code only.

    Declaration

    Objective-C

    #define NSImageRepRegistryChangedNotification NSImageRepRegistryDidChangeNotification

    Constants

    • NSImageRepRegistryChangedNotification

      NSImageRepRegistryChangedNotification

      An older name for the NSImageRepRegistryDidChangeNotification notification. Do not use.

      Available in OS X v10.0 and later.

    Import Statement