NSImageRep Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSImageRep.h

Overview

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.

Tasks

Creating an NSImageRep

Determining the Supported Image Types

Setting the Size of the Image

Specifying Information About the Representation

Getting a CGImage

Drawing the Image

Managing NSImageRep Subclasses

Class Methods

canInitWithData:

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

+ (BOOL)canInitWithData:(NSData *)data
Parameters
data

The image data.

Return Value

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

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 NO only if it knows it cannot initialize itself from the data.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

canInitWithPasteboard:

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

+ (BOOL)canInitWithPasteboard:(NSPasteboard *)pasteboard
Parameters
pasteboard

The pasteboard containing the image data.

Return Value

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

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 YES. 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageFileTypes

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imagePasteboardTypes

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepClassForData:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepClassForFileType:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepClassForPasteboardType:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepClassForType:

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

+ (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSImageRep.h

imageRepsWithContentsOfFile:

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

+ (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”.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepsWithContentsOfURL:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepsWithPasteboard:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepWithContentsOfFile:

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

+ (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”.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageRepWithContentsOfURL:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSImageRep.h

imageRepWithPasteboard:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageTypes

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

+ (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSImageRep.h

imageUnfilteredFileTypes

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageUnfilteredPasteboardTypes

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

imageUnfilteredTypes

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

+ (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSImageRep.h

registeredImageRepClasses

Returns an array containing the registered NSImageRep classes.

+ (NSArray *)registeredImageRepClasses
Return Value

An array of Class objects identifying the registered NSImageRep subclasses.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

registerImageRepClass:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSImageRep.h

unregisterImageRepClass:

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

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

Instance Methods

bitsPerSample

Returns the number of bits per sample in the receiver.

- (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.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSImageRep.h

CGImageForProposedRect:context:hints:

Returns a CGImage capturing the drawing of the receiver.

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSImageRep.h

colorSpaceName

Returns the name of the receiver's color space.

- (NSString *)colorSpaceName
Return Value

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

draw

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

- (BOOL)draw
Return Value

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

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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSImageRep.h

drawAtPoint:

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

- (BOOL)drawAtPoint:(NSPoint)aPoint
Parameters
aPoint

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

Return Value

YES if the image was successfully drawn; otherwise, NO. If the size of the image has not yet been set, this method returns NO 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

drawInRect:

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

- (BOOL)drawInRect:(NSRect)rect
Parameters
rect

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

Return Value

YES if the image was successfully drawn; otherwise, NO. If the size of the image has not yet been set, this method returns NO 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

drawInRect:fromRect:operation:fraction:respectFlipped:hints:

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

- (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

YES if the flipped context of the receiver should be respected, otherwise NO.

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

YES if the image was successfully drawn; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.6 and later.
Declared In
NSImageRep.h

hasAlpha

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

- (BOOL)hasAlpha
Return Value

YES if the receiver has a known alpha channel; otherwise, NO.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

isOpaque

Returns a Boolean value indicating whether the receiver is opaque.

- (BOOL)isOpaque
Return Value

YES if the receiver is opaque; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

pixelsHigh

Returns the height of the image, measured in pixels.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

pixelsWide

Returns the width of the image, measured in pixels.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

setAlpha:

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

- (void)setAlpha:(BOOL)flag
Parameters
flag

YES if you want the receiver to have an alpha component; otherwise NO.

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 YES does not add an alpha channel to the image data itself; it merely records the fact that the data has an alpha channel.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSImageRep.h

setBitsPerSample:

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

- (void)setBitsPerSample:(NSInteger)anInt
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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

setColorSpaceName:

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

- (void)setColorSpaceName:(NSString *)string
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:

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

setOpaque:

Sets whether the receiver's image is opaque.

- (void)setOpaque:(BOOL)flag
Parameters
flag

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

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSImageRep.h

setPixelsHigh:

Informs the receiver of the image data height.

- (void)setPixelsHigh:(NSInteger)anInt
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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

setPixelsWide:

Informs the receiver of the image data width.

- (void)setPixelsWide:(NSInteger)anInt
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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

setSize:

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

- (void)setSize:(NSSize)aSize
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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSImageRep.h

size

Returns the size of the image representation.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSImageRep.h

Constants

Display Device Matching

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

enum {
   NSImageRepMatchesDevice
};
Constants
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.

Declared in NSImageRep.h.

Deprecated Notification Name

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

#define NSImageRepRegistryChangedNotification NSImageRepRegistryDidChangeNotification
Constants
NSImageRepRegistryChangedNotification

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

Available in OS X v10.0 and later.

Declared in NSImageRep.h.

Notifications

NSImageRepRegistryDidChangeNotification

Posted whenever the NSImageRep class registry changes.

The notification object is the image class that is registered or unregistered. This notification does not contain a userInfo dictionary.

Availability
Declared In
NSImageRep.h