Inherits from: NSObject
Conforms to: NSCoding
NSCopying
NSObject (NSObject)
Declared in: AppKit/NSImageRep.h
NSImageRep is a semi-abstract 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's typically used through an NSImage object. An NSImage manages a group of representations, choosing the best one for the current output device.
There are four subclasses defined in the Application Kit:
Subclass | Source Data |
NSBitmapImageRep | Tag Image File Format (TIFF), Windows bitmap (BMP) and other bitmap data |
NSCachedImageRep | A rendered image, usually in an off-screen window |
NSCustomImageRep | A delegated method that can draw the image |
NSEPSImageRep | Encapsulated PostScript code (EPS) |
You can define other NSImageRep subclasses for objects that render images from other types of source information. New subclasses must be added to the NSImageRep class registry by invoking the registerImageRepClass: class method. The NSImageRep subclass informs the registry of the data types it can support through its imageUnfilteredFileTypes, imageUnfilteredPasteboardTypes, and canInitWithData: class methods. Once an NSImageRep subclass is registered, an instance of that subclass is created any time NSImage encounters the type of data handled by that subclass.
Subclasses which deal with file and pasteboard types should implement imageUnfilteredFileTypes, imageUnfilteredPasteboardTypes, initWithData:, canInitWithData:, and, if they have the ability to read multiple images from a file, imageRepsWithData:. These last three should not do any filtering; all filtering is automatic.
- NSCoding
- - encodeWithCoder:
- - initWithCoder:
- NSCopying
- - copyWithZone:
- Creating an NSImageRep
- + imageRepsWithContentsOfFile:
- + imageRepsWithPasteboard:
- + imageRepWithContentsOfFile:
- + imageRepWithPasteboard:
- Checking data types
- + canInitWithData:
- + canInitWithPasteboard:
- + imageFileTypes
- + imagePasteboardTypes
- + imageUnfilteredFileTypes
- + imageUnfilteredPasteboardTypes
- Setting the size of the image
- - setSize:
- - size
- Specifying information about the representation
- - bitsPerSample
- - colorSpaceName
- - hasAlpha
- - isOpaque
- - pixelsHigh
- - pixelsWide
- - setAlpha:
- - setBitsPerSample:
- - setColorSpaceName:
- - setOpaque:
- - setPixelsHigh:
- - setPixelsWide:
- Drawing the image
- - draw
- - drawAtPoint:
- - drawInRect:
- Managing NSImageRep subclasses
- + imageRepClassForData:
- + imageRepClassForFileType:
- + imageRepClassForPasteboardType:
- + registeredImageRepClasses
- + registerImageRepClass:
- + unregisterImageRepClass:
+ (BOOL)canInitWithData:(NSData *)data
+ (BOOL)canInitWithPasteboard:(NSPasteboard *)pasteboard
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.
+ (NSArray *)imageFileTypes
+ (NSArray *)imagePasteboardTypes
+ (Class)imageRepClassForData:(NSData *)data
nil
if
the NSImage class registry contains no subclasses that handle data
of the specified type.+ (Class)imageRepClassForFileType:(NSString *)type
nil
if the NSImage
class registry contains no subclasses that handle files of the specified type.+ (Class)imageRepClassForPasteboardType:(NSString
*)type
nil
if
the NSImage class registry contains no subclasses that handle pasteboard
data of the specified type.+ (id)imageRepWithContentsOfFile:(NSString *)filename
imageRepWithContentsOfFile: returns nil
in
any of the following cases:
filename may be a full or relative pathname, and should include an extension that identifies the data type in the file. By default, the files handled are those with the extensions "tiff", "tif", "bmp", and "eps".
The NSImageRep subclass is initialized by creating an NSData object based on the contents of the file, then passing it to imageRepWithData:.
See Also: + imageFileTypes
+ (id)imageRepWithPasteboard:(NSPasteboard *)pasteboard
imageRepWithPasteboard: returns nil
in
any of the following cases:
The NSImageRep subclass is initialized by creating an NSData object based on the data in pasteboard, then passing it to imageRepWithData:.
See Also: + imagePasteboardTypes
+ (NSArray *)imageRepsWithContentsOfFile:(NSString
*)filename
imageRepsWithContentsOfFile: returns nil
in
any of the following cases:
filename may be a full or relative pathname, and should include an extension that identifies the data type in the file. By default, the files handled are those with the extensions "tiff", "tif", "bmp", and "eps".
The NSImageRep subclass is initialized by creating an NSData object based on the contents of the file, then passing it to imageRepsWithData:.
See Also: + imageFileTypes
+ (NSArray *)imageRepsWithPasteboard:(NSPasteboard
*)pasteboard
imageRepsWithPasteboard: returns nil
in
any of the following cases:
The NSImageRep subclass is initialized by creating an NSData object based on the data in pasteboard, then passing it to imageRepsWithData:.
See Also: + imagePasteboardTypes
+ (NSArray *)imageUnfilteredFileTypes
When creating a subclass of NSImageRep, override this method to return a list of strings representing the supported file types. For example, NSBitmapImageRep implements the following code for this method:
+ (NSArray *)imageUnfilteredFileTypes { static NSArray *types = nil; if (!types) types = [[NSArray alloc] initWithObjects:@"tiff", @"tif", @"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.
See Also: + imageFileTypes, + imageUnfilteredFileTypes (NSImage)
+ (NSArray *)imageUnfilteredPasteboardTypes
When creating a subclass of NSImageRep, override this method to return a list representing the supported pasteboard types. For example, NSBitmapImageRep implements the following code 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.
See Also: + imagePasteboardTypes, + imageUnfilteredPasteboardTypes (NSImage)
+ (void)registerImageRepClass:(Class)imageRepClass
A good place to add image representation classes to the registry is in the load class method.
See Also: + load (NSObject)
+ (NSArray *)registeredImageRepClasses
+ (void)unregisterImageRepClass:(Class)imageRepClass
- (int)bitsPerSample
- (NSString *)colorSpaceName
- (BOOL)draw
- (BOOL)drawAtPoint:(NSPoint)aPoint
This method returns NO without translating, scaling, or drawing if the size of the image has not been set. Otherwise it returns the value returned by the draw method, which indicates whether the image is successfully drawn.
See Also: - setSize:
- (BOOL)drawInRect:(NSRect)rect
This method returns NO without translating, scaling, or drawing if the size of the image has not been set. Otherwise it returns the value returned by the draw method, which indicates whether the image is successfully drawn.
See Also: - setSize:
- (BOOL)hasAlpha
- (BOOL)isOpaque
- (int)pixelsHigh
See Also: - size
- (int)pixelsWide
See Also: - size
- (void)setAlpha:(BOOL)flag
- (void)setBitsPerSample:(int)anInt
- (void)setColorSpaceName:(NSString *)string
NSGraphics.h
.
The following are valid color space names:- (void)setOpaque:(BOOL)flag
- (void)setPixelsHigh:(int)anInt
See Also: - setSize:
- (void)setPixelsWide:(int)anInt
See Also: - setSize:
- (void)setSize:(NSSize)aSize
See Also: - draw, - setPixelsHigh:, - setPixelsWide:
- (NSSize)size
See Also: - pixelsHigh, - pixelsWide
Posted whenever the NSImageRep class registry changes.
This notification contains a notification object but no userInfo dictionary. The notification object is the image class that is registered or unregistered.