NSCustomImageRep 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
NSCustomImageRep.h
Related sample code

Overview

An NSCustomImageRep object uses a delegate object to render an image. When called upon to produce an image, it sends a message to its delegate to do the actual drawing. You can use this class to support custom image formats without going to the trouble of subclassing NSImageRep directly.

Tasks

Initializing a New NSCustomImageRep

Getting the Custom Image Drawing Handler Destination Rectangle

Identifying the Object

Instance Methods

delegate

Returns the delegate object that renders the image for the receiver.

- (id)delegate
Return Value

The delegate object.

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

drawingHandler

Returns the destination rectangle of the drawing handler Block.

- (NSRect dstRect)drawingHandler
Return Value

The destination rectangle of the drawing handler Block.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSCustomImageRep.h

drawSelector

Returns the selector for the delegate's drawing method.

- (SEL)drawSelector
Return Value

The selector for the delegate's drawing method.

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

initWithDrawSelector:delegate:

Returns an NSCustomImageRep object initialized with the specified delegate information.

- (id)initWithDrawSelector:(SEL)aMethod delegate:(id)anObject
Parameters
aMethod

The selector to call when it is time to draw the image. The method should take a single parameter of type id that represents the NSCustomImageRep object that initiated drawing. The method must draw the image starting at the point (0, 0) in the current coordinate system.

anObject

The delegate object that responds to the selector in aMethod.

Return Value

An initialized NSCustomImageRep object, or nil if the object could not be initialized.

Discussion

When the receiver is asked to draw the image, it sends the specified message to the selector, passing itself as a parameter to the delegate method. The delegate's drawing method should have the following form:

- (void)myCustomDrawMethod:(id)anNSCustomImageRep;
Availability
  • Available in OS X v10.0 and later.
See Also
Related Sample Code
Declared In
NSCustomImageRep.h

initWithSize:flipped:drawingHandler:

Initializes an image representation of the specified size and flipped status, using a Block to draw its content.

- (id)initWithSize:(NSSize)size flipped:(BOOL)drawingHandlerShouldBeCalledWithFlippedContext drawingHandler:(BOOL (^)(NSRect dstRect))drawingHandler
Parameters
size

The size of the image.

drawingHandlerShouldBeCalledWithFlippedContext

YES if the drawing handler should be called with a flipped graphics context; otherwise NO.

drawingHandler

A Block that draws the image rep content in the provided graphics context.

The block may be invoked whenever and on whatever thread the image itself is drawn on. Care should be taken to ensure that all state accessed within the drawingHandler block is done so in a thread safe manner.

This Block replaces the lockFocus and unlockFocus technique of creating drawing content. The block is invoked at draw time, the drawing can be adjusted to suit the destination’s pixel density, color space, and other properties.

Return Value

An initialized NSCustomImageRep object, or nil if the object could not be initialized.

Discussion

Using the this method ensures you’ll get correct results under standard and high resolution.

Like other non-bitmap image rep types, drawing is cached as appropriate for the destination context. Practically speaking, the drawingHandler block will be invoked the first time the image is drawn to a particular type of destination (1x or 2x screen, for example). Subsequent drawing operations to the same type of destination will reuse the previously generated bitmap.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSCustomImageRep.h