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 |
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.
Return Value
The delegate object.
Availability
- Available in OS X v10.0 and later.
Declared In
NSCustomImageRep.hdrawingHandler
Returns the destination rectangle of the drawing handler Block.
Return Value
The destination rectangle of the drawing handler Block.
Availability
- Available in OS X v10.8 and later.
Declared In
NSCustomImageRep.hdrawSelector
Returns the selector for the delegate's drawing method.
Return Value
The selector for the delegate's drawing method.
Availability
- Available in OS X v10.0 and later.
Declared In
NSCustomImageRep.hinitWithDrawSelector:delegate:
Returns an NSCustomImageRep object initialized with the specified delegate information.
Parameters
- aMethod
The selector to call when it is time to draw the image. The method should take a single parameter of type
idthat represents theNSCustomImageRepobject 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
-
draw(NSImageRep)
Declared In
NSCustomImageRep.hinitWithSize:flipped:drawingHandler:
Initializes an image representation of the specified size and flipped status, using a Block to draw its content.
Parameters
- size
The size of the image.
- drawingHandlerShouldBeCalledWithFlippedContext
YESif the drawing handler should be called with a flipped graphics context; otherwiseNO.- 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
lockFocusandunlockFocustechnique 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.
See Also
Declared In
NSCustomImageRep.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)