Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSBitmapImageRep.h |
Related sample code |
An NSBitmapImageRep
is an object that can render an image from bitmap data. Bitmap data formats supported include GIF, JPEG, TIFF, PNG, and various permutations of raw bitmap data.
If a coverage (alpha) plane exists, a bitmap’s color components are premultiplied with it. If you modify the contents of the bitmap, you are therefore responsible for premultiplying the data. For this reason, though, if you want to manipulate the actual data, an NSBitmapImageRep
object is not recommended for storage. If you need to work with unpremultiplied data, you should use Quartz, specifically CGImageCreate
with kCGImageAlphaLast
.
Note that premultiplying does not affect the output quality. Given source bitmap pixel s
, destination pixel d
, and alpha value a
, a blend is basically
d' = a * s + (1 - a) * d |
All premultiplication does is precalculate a * s
.
+ imageRepWithData:
+ imageRepsWithData:
– colorizeByMappingGray:toColor:blackMapping:whiteMapping:
– initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:
– initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
– initWithCGImage:
– initWithCIImage:
– initWithData:
– initWithFocusedViewRect:
– initForIncrementalLoad
– bitmapFormat
– bitsPerPixel
– bytesPerPlane
– bytesPerRow
– isPlanar
– numberOfPlanes
– samplesPerPixel
+ TIFFRepresentationOfImageRepsInArray:
+ TIFFRepresentationOfImageRepsInArray:usingCompression:factor:
– TIFFRepresentation
– TIFFRepresentationUsingCompression:factor:
+ representationOfImageRepsInArray:usingType:properties:
– representationUsingType:properties:
+ getTIFFCompressionTypes:count:
+ localizedNameForTIFFCompressionType:
– canBeCompressedUsing:
– setCompression:factor:
– getCompression:factor:
– setProperty:withValue:
– valueForProperty:
Returns by indirection an array of all available compression types that can be used when writing a TIFF image.
+ (void)getTIFFCompressionTypes:(const NSTIFFCompression **)list count:(NSInteger *)numTypes
On return, a C array of NSTIFFCompression
constants. This array belongs to the NSBitmapImageRep
class; it shouldn’t be freed or altered. See “Constants” for the supported TIFF compression types.
The number of constants in list.
Note that not all compression types can be used for all images: NSTIFFCompressionNEXT
can be used only to retrieve image data. Because future releases may include other compression types, always use this method to get the available compression types—for example, when you implement a user interface for selecting compression types.
NSBitmapImageRep.h
Creates and returns an array of initialized NSBitmapImageRep
objects corresponding to the images in the supplied data.
+ (NSArray *)imageRepsWithData:(NSData *)bitmapData
A data object containing one or more bitmapped images or nil
if the class is unable to create an image representation. The bitmapData parameter can contain data in any supported bitmap format.
An array of NSBitmapImageRep
instances or an empty array if the class is unable to create any image representations.
NSBitmapImageRep.h
Creates and returns an NSBitmapImageRep
object initialized with the first image in the supplied data.
+ (id)imageRepWithData:(NSData *)bitmapData
A data object containing one or more bitmapped images. The bitmapData parameter can contain data in any supported bitmap format.
An NSBitmapImageRep
instance or nil
if the class is unable to create an image representation.
NSBitmapImageRep.h
Returns an autoreleased string containing the localized name for the specified compression type.
+ (NSString *)localizedNameForTIFFCompressionType:(NSTIFFCompression)compression
A TIFF compression type. NSTIFFCompression
types are described in “Constants.”
A localized name for compression or nil
if compression is unrecognized.
When implementing a user interface for selecting TIFF compression types, use getTIFFCompressionTypes:count:
to get the list of supported compression types, then use this method to get the localized names for each compression type.
NSBitmapImageRep.h
Formats the specified bitmap images using the specified storage type and properties and returns them in a data object.
+ (NSData *)representationOfImageRepsInArray:(NSArray *)imageReps usingType:(NSBitmapImageFileType)storageType properties:(NSDictionary *)properties
An array of NSBitmapImageRep
objects.
An enum
constant specifying a file type for bitmap images. It can be NSBMPFileType
, NSGIFFileType
, NSJPEGFileType
, NSPNGFileType
, or NSTIFFFileType
.
A dictionary that contains key-value pairs specifying image properties. These string constants used as keys and the valid values are described in “Bitmap image properties.”
A data object containing the bitmap image data in the specified format. You can write this data to a file or use it to create a new NSBitmapImageRep
object.
NSBitmapImageRep.h
Returns a TIFF representation of the given images
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)array
An array containing objects representing bitmap image representations.
A data object containing a TIFF image representation.
This method uses the compression returned by getCompression:factor:
(if applicable). If a problem is encountered during generation of the TIFF, this method raises an NSTIFFException
or an NSBadBitmapParametersException
.
NSBitmapImageRep.h
Returns a TIFF representation of the given images using a specified compression scheme and factor.
+ (NSData *)TIFFRepresentationOfImageRepsInArray:(NSArray *)array usingCompression:(NSTIFFCompression)compression factor:(float)factor
An array containing objects representing bitmap image representations.
An enum constant that represents a TIFF data-compression scheme. Legal values for compression can be found in NSBitmapImageRep.h
and are described in “Constants.”
A float
value that provides a hint for those compression types that implement variable compression ratios.
Currently only JPEG compression uses a compression factor. JPEG compression in TIFF files is not supported, and factor is ignored.
A data object containing a TIFF image representation.
If the specified compression isn’t applicable, no compression is used. If a problem is encountered during generation of the TIFF, the method raises an NSTIFFException
or an NSBadBitmapParametersException
.
NSBitmapImageRep.h
Returns a pointer to the bitmap data.
- (unsigned char *)bitmapData
If the data is planar, returns a pointer to the first plane.
NSBitmapImageRep.h
Returns the bitmap format of the receiver.
- (NSBitmapFormat)bitmapFormat
Returns 0 by default. The return value can indicate several different attributes, which are described in “Constants.”
NSBitmapImageRep.h
Returns the number of bits allocated for each pixel in each plane of data.
- (NSInteger)bitsPerPixel
This number is normally equal to the number of bits per sample or, if the data is in meshed configuration, the number of bits per sample times the number of samples per pixel. It can be explicitly set to another value (in initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
) in case extra memory is allocated for each pixel. This may be the case, for example, if pixel data is aligned on byte boundaries.
NSBitmapImageRep.h
Returns the number of bytes in each plane or channel of data.
- (NSInteger)bytesPerPlane
This number is calculated from the number of bytes per row and the height of the image.
NSBitmapImageRep.h
Returns the minimum number of bytes required to specify a scan line (a single row of pixels spanning the width of the image) in each data plane.
- (NSInteger)bytesPerRow
If not explicitly set to another value (in initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
), this number will be figured from the width of the image, the number of bits per sample, and, if the data is in a meshed configuration, the number of samples per pixel. It can be set to another value to indicate that each row of data is aligned on word or other boundaries.
NSBitmapImageRep.h
Tests whether the receiver can be compressed by the specified compression scheme.
- (BOOL)canBeCompressedUsing:(NSTIFFCompression)compression
A TIFF compression type. NSTIFFCompression
types are defined in “Constants.”
YES
if the receiver's data matches compression
with this type, NO
if the data doesn’t match compression or if compression is unsupported..
Legal values for compression can be found in NSBitmapImageRep.h
and are described in TIFF Compression in NSBitmapImageReps. This method returns YES
if the receiver’s data matches compression; for example, if compression is NSTIFFCompressionCCITTFAX3
, then the data must be 1 bit per sample and 1 sample per pixel.
NSBitmapImageRep.h
Returns a Core Graphics image object from the receiver’s current bitmap data.
- (CGImageRef)CGImage
Returns an autoreleased CGImageRef
opaque type based on the receiver’s current bitmap data.
The returned CGImageRef
has pixel dimensions that are identical to the receiver’s. This method might return a preexisting CGImageRef
opaque type or create a new one. If the receiver is later modified, subsequent invocations of this method might return different CGImageRef
opaque types.
NSBitmapImageRep.h
Returns the color of the pixel at the specified coordinates.
- (NSColor *)colorAtX:(NSInteger)x y:(NSInteger)y
The x-axis coordinate.
The y-axis coordinate.
A color object representing the color at the specified coordinates.
NSBitmapImageRep.h
Colorizes a grayscale image.
- (void)colorizeByMappingGray:(CGFloat)midPoint toColor:(NSColor *)midPointColor blackMapping:(NSColor *)shadowColor whiteMapping:(NSColor *)lightColor
A float value representing the midpoint of the grayscale image.
A color object representing the midpoint of the color to map the image to.
A color object representing the black mapping to use for shadows.
A color object representing the white mapping to be used in the image.
This method maps the receiver such that:
Gray value of midPoint –> midPointColor;
black –> shadowColor;
white –> lightColor.
It works on images with 8-bit SPP, and thus supports either 8-bit gray or 24-bit color (with optional alpha).
NSBitmapImageRep.h
Returns by indirection bitmap data of the receiver separated into planes.
- (void)getBitmapDataPlanes:(unsigned char **)data
On return, a C array of five character pointers. If the bitmap data is in planar configuration, each pointer will be initialized to point to one of the data planes. If there are less than five planes, the remaining pointers will be set to NULL
. If the bitmap data is in meshed configuration, only the first pointer will be initialized; the others will be NULL
.
Color components in planar configuration are arranged in the expected order—for example, red before green before blue for RGB color. All color planes precede the coverage plane. If a coverage plane exists, the bitmap’s color components are premultiplied with it. If you modify the contents of the bitmap, you are responsible for premultiplying the data.
– isPlanar
– initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:
– initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:
NSBitmapImageRep.h
Returns by indirection the receiver’s compression type and compression factor.
- (void)getCompression:(NSTIFFCompression *)compression factor:(float *)factor
On return, an enum
constant that represents the compression type used on the data; it corresponds to one of the values returned by the class method getTIFFCompressionTypes:count:
.
A float value that is specific to the compression type. Many types of compression don’t support varying degrees of compression and thus ignore factor. JPEG compression allows a compression factor ranging from 0.0 to 1.0, with 0.0 being the lowest and 1.0 being the highest.
Use this method to get information on the compression type for the source image data.
NSBitmapImageRep.h
Returns by indirection the pixel data for the specified location in the receiver.
- (void)getPixel:(NSUInteger[])pixelData atX:(NSInteger)x y:(NSInteger)y
On return, an array of integers containing raw pixel data in the appropriate order for the receiver’s bitmapFormat
. Smaller integer samples, such as 4-bit, are returned as an integer. Floating point values are cast to integer values and returned.
The x-axis coordinate of the pixel.
The y-axis coordinate of the pixel.
NSBitmapImageRep.h
Loads the current image data into an incrementally-loaded image representation and returns the current status of the image.
- (NSInteger)incrementalLoadFromData:(NSData *)data complete:(BOOL)complete
A data object that contains the image to be loaded.
YES
if the image is entirely downloaded, NO
otherwise.
An integer constant indicating the status of the image during the load operation. See the discussion for details.
After initializing the receiver with initForIncrementalLoad
, you should call this method to incrementally load the image. Call this method each time new data becomes available. Always pass the entire image data buffer in data, not just the newest data, because the image decompressor may need the original data in order to backtrack. This method will block until the data is decompressed; it will decompress as much of the image as possible based on the length of the data. The image rep does not retain data, so you must ensure that data is not released for the duration of this method call. Pass NO
for complete until the entire image is downloaded, at which time you should pass YES
. You should also pass YES
for complete if you have only partially downloaded the data, but cannot finish the download.
This method returns NSImageRepLoadStatusUnknownType
if you did not pass enough data to determine the image format; you should continue to invoke this method with additional data.
This method returns NSImageRepLoadStatusReadingHeader
if it has enough data to determine the image format, but needs more data to determine the size and depth and other characteristics of the image. You should continue to invoke this method with additional data.
This method returns NSImageRepLoadStatusWillNeedAllData
if the image format does not support incremental loading or the Application Kit does not yet implement incremental loading for the image format. You may continue to invoke this method in this case, but until you pass YES
for complete, this method will continue to return NSImageRepLoadStatusWillNeedAllData
, and will perform no decompression. Once you pass YES
, the image will be decompressed and one of the final three status messages will be returned.
If the image format does support incremental loading, then once enough data has been read, the image is decompressed from the top down a row at a time. In this case, instead of a status value, this method returns the number of pixel rows that have been decompressed, starting from the top of the image. You can use this information to draw the part of the image that is valid. The rest of the image is filled with opaque white. Note that if the image is progressive (as in a progressive JPEG or 2D interlaced PNG), this method may quickly return the full height of the image, but the image may still be loading, so do not use this return value as an indication of how much of the image remains to be decompressed.
If an error occurred while decompressing, this method returns NSImageRepLoadStatusInvalidData
. If complete is YES
but not enough data was available for decompression, NSImageRepLoadStatusUnexpectedEOF
is returned. If enough data has been provided (regardless of the complete flag), then NSImageRepLoadStatusCompleted
is returned. When any of these three status results are returned, this method has adjusted the NSBitmapImageRep
so that pixelsHigh
and size
, as well as the bitmap data, only contains the pixels that are valid, if any.
To cancel decompression, just pass in the existing data or nil
and YES
for complete. This method stops decompression immediately, adjusts the image size, and returns NSImageRepLoadStatusUnexpectedEOF
. This method returns NSImageRepLoadStatusCompleted
if you call it after receiving any error results (NSImageRepLoadStatusInvalidData
or NSImageRepLoadStatusUnexpectedEOF
) or if you call it on an NSBitmapImageRep
that was not initialized with initForIncrementalLoad
.
NSBitmapImageRep.h
Initializes and returns the receiver, a newly allocated NSBitmapImageRep
object, for incremental loading.
- (id)initForIncrementalLoad
The receiver returns itself after setting its size and data buffer to zero. You can then call incrementalLoadFromData:complete:
to incrementally add image data.
NSBitmapImageRep.h
Initializes the receiver, a newly allocated NSBitmapImageRep
object, so it can render the specified image.
- (id)initWithBitmapDataPlanes:(unsigned char **)planes pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString *)colorSpaceName bitmapFormat:(NSBitmapFormat)bitmapFormat bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits
An array of character pointers, each of which points to a buffer containing raw image data. If the data is in planar configuration, each buffer holds one component—one plane—of the data. Color planes are arranged in the standard order—for example, red before green before blue for RGB color. All color planes precede the coverage plane. If a coverage plane exists, the bitmap’s color components must be premultiplied with it. If the data is in meshed configuration (that is, isPlanar is NO
), only the first buffer is read.
If planes is NULL
or an array of NULL
pointers, this method allocates enough memory to hold the image described by the other arguments. You can then obtain pointers to this memory (with the getPixel:atX:y:
or bitmapData
method) and fill in the image data. In this case, the allocated memory will belong to the object and will be freed when it’s freed.
If planes is not NULL
and the array contains at least one data pointer, the returned object will only reference the image data; it will not copy it. The object treats the image data in the buffers as immutable and will not attempt to alter it. When the object itself is freed, it will not attempt to free the buffers.
The width of the image in pixels. This value must be greater than 0.
The height of the image in pixels. This value must be greater than 0.
The number of bits used to specify one pixel in a single component of the data. All components are assumed to have the same bits per sample. bps should be one of these values: 1, 2, 4, 8, 12, or 16.
The number of data components, or samples per pixel. This value includes both color components and the coverage component (alpha), if present. Meaningful values range from 1 through 5. An image with cyan, magenta, yellow, and black (CMYK) color components plus a coverage component would have an spp of 5; a grayscale image that lacks a coverage component would have an spp of 1.
YES
if one of the components counted in the number of samples per pixel (spp) is a coverage (alpha) component, and NO
if there is no coverage component. If YES
, the color components in the bitmap data must be premultiplied with their coverage component.
YES
if the data components are laid out in a series of separate “planes” or channels (“planar configuration”) and NO
if component values are interwoven in a single channel (“meshed configuration”). If NO
, only the first buffer of planes
is read.
For example, in meshed configuration, the red, green, blue, and coverage values for the first pixel of an image would precede the red, green, blue, and coverage values for the second pixel, and so on. In planar configuration, red values for all the pixels in the image would precede all green values, which would precede all blue values, which would precede all coverage values.
A string constant that indicates how data values are to be interpreted. It should be one of the following values:
If bps is 12, you cannot specify the monochrome color space.
An integer that specifies the ordering of the bitmap components. It is a mask created by combining the NSBitmapFormat
constants NSAlphaFirstBitmapFormat
, NSAlphaNonpremultipliedBitmapFormat
and NSFloatingPointSamplesBitmapFormat
using the C bitwise OR operator.
The number of bytes that are allocated for each scan line in each plane of data. A scan line is a single row of pixels spanning the width of the image.
Normally, rowBytes can be figured from the width of the image, the number of bits per pixel in each sample (bps), and, if the data is in a meshed configuration, the number of samples per pixel (spp). However, if the data for each row is aligned on word or other boundaries, it may have been necessary to allocate more memory for each row than there is data to fill it. rowBytes lets the object know whether that’s the case.
If you pass in a rowBytes value of 0, the bitmap data allocated may be padded to fall on long word or larger boundaries for performance. If your code wants to advance row by row, use bytesPerRow
and do not assume the data is packed. Passing in a non-zero value allows you to specify exact row advances.
This integer value informs NSBitmapImageRep
how many bits are actually allocated per pixel in each plane of data. If the data is in planar configuration, this normally equals bps (bits per sample). If the data is in meshed configuration, it normally equals bps times spp (samples per pixel). However, it’s possible for a pixel specification to be followed by some meaningless bits (empty space), as may happen, for example, if pixel data is aligned on byte boundaries. NSBitmapImageRep
supports only a limited number of pixelBits values (other than the default): for RGB images with 4 bps, pixelBits may be 16; for RGB images with 8 bps, pixelBits may be 32. The legal values for pixelBits are system dependent.
If you specify 0 for this parameter, the object interprets the number of bits per pixel using the values in the bps and spp parameters, as described in the preceding paragraph, without any meaningless bits.
An initialized NSBitmapImageRep
object or nil
if the object cannot be initialized.
NSBitmapImageRep.h
Initializes the receiver, a newly allocated NSBitmapImageRep
object, so it can render the specified image.
- (id)initWithBitmapDataPlanes:(unsigned char **)planes pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString *)colorSpaceName bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits
An array of character pointers, each of which points to a buffer containing raw image data. If the data is in planar configuration, each buffer holds one component—one plane—of the data. Color planes are arranged in the standard order—for example, red before green before blue for RGB color. All color planes precede the coverage plane. If a coverage plane exists, the bitmap’s color components must be premultiplied with it. If the data is in meshed configuration (that is, isPlanar is NO
), only the first buffer is read.
If planes is NULL
or an array of NULL
pointers, this method allocates enough memory to hold the image described by the other arguments. You can then obtain pointers to this memory (with the getPixel:atX:y:
or bitmapData
method) and fill in the image data. In this case, the allocated memory will belong to the object and will be freed when it’s freed.
If planes is not NULL
and the array contains at least one data pointer, the returned object will only reference the image data; it will not copy it. The object treats the image data in the buffers as immutable and will not attempt to alter it. When the object itself is freed, it will not attempt to free the buffers.
The width of the image in pixels. This value must be greater than 0.
The height of the image in pixels. This value must be greater than 0.
The number of bits used to specify one pixel in a single component of the data. All components are assumed to have the same bits per sample. bps should be one of these values: 1, 2, 4, 8, 12, or 16.
The number of data components, or samples per pixel. This value includes both color components and the coverage component (alpha), if present. Meaningful values range from 1 through 5. An image with cyan, magenta, yellow, and black (CMYK) color components plus a coverage component would have an spp of 5; a grayscale image that lacks a coverage component would have an spp of 1.
YES
if one of the components counted in the number of samples per pixel (spp) is a coverage (alpha) component, and NO
if there is no coverage component. If YES
, the color components in the bitmap data must be premultiplied with their coverage component.
YES
if the data components are laid out in a series of separate “planes” or channels (“planar configuration”) and NO
if component values are interwoven in a single channel (“meshed configuration”). If NO
, only the first buffer of planes
is read.
For example, in meshed configuration, the red, green, blue, and coverage values for the first pixel of an image would precede the red, green, blue, and coverage values for the second pixel, and so on. In planar configuration, red values for all the pixels in the image would precede all green values, which would precede all blue values, which would precede all coverage values.
A string constant that indicates how data values are to be interpreted. It should be one of the following values:
If bps is 12, you cannot specify the monochrome color space.
The number of bytes that are allocated for each scan line in each plane of data. A scan line is a single row of pixels spanning the width of the image.
Normally, rowBytes can be figured from the width of the image, the number of bits per pixel in each sample (bps), and, if the data is in a meshed configuration, the number of samples per pixel (spp). However, if the data for each row is aligned on word or other boundaries, it may have been necessary to allocate more memory for each row than there is data to fill it. rowBytes lets the object know whether that’s the case.
If you pass in a rowBytes value of 0, the bitmap data allocated may be padded to fall on long word or larger boundaries for performance. If your code wants to advance row by row, use bytesPerRow
and do not assume the data is packed. Passing in a non-zero value allows you to specify exact row advances.
This integer value informs NSBitmapImageRep
how many bits are actually allocated per pixel in each plane of data. If the data is in planar configuration, this normally equals bps (bits per sample). If the data is in meshed configuration, it normally equals bps times spp (samples per pixel). However, it’s possible for a pixel specification to be followed by some meaningless bits (empty space), as may happen, for example, if pixel data is aligned on byte boundaries. NSBitmapImageRep
supports only a limited number of pixelBits values (other than the default): for RGB images with 4 bps, pixelBits may be 16; for RGB images with 8 bps, pixelBits may be 32. The legal values for pixelBits are system dependent.
If you specify 0 for this parameter, the object interprets the number of bits per pixel using the values in the bps and spp parameters, as described in the preceding paragraph, without any meaningless bits.
An initialized NSBitmapImageRep
object or nil
if the object cannot be initialized.
NSBitmapImageRep.h
Returns an NSBitmapImageRep
object created from a Core Graphics image object.
- (id)initWithCGImage:(CGImageRef)cgImage
A Core Graphics image object (an opaque type) from which to create the receiver. This opaque type is retained.
An NSBitmapImageRep
object initialized from the contents of the Core Graphics image or nil
if the NSBitmapImageRep
couldn’t be created.
If you use this method, you should treat the resulting bitmap NSBitmapImageRep
object as read only. Because it only retains the value in the cgImage parameter, rather than unpacking the data, accessing the pixel data requires the creation of a copy of that data in memory. Changes to that data are not saved back to the Core Graphics image.
NSBitmapImageRep.h
Returns an NSBitmapImageRep
object created from a Core Image object.
- (id)initWithCIImage:(CIImage *)ciImage
A Core Image object whose contents are to be copied to the receiver. This image rectangle must be of a finite size.
An NSBitmapImageRep
object initialized from the contents of the Core Image (CIImage
) object or nil
if the NSBitmapImageRep
couldn’t be created.
The image in the ciImage parameter must be fully rendered before the receiver can be initialized. If you specify an object whose rendering was deferred (and thus does not have any pixels available now), this method forces the image to be rendered immediately. Rendering the image could result in a performance penalty if the image has a complex rendering chain or accelerated rendering hardware is not available. By the time this method returns, however, the resultant NSBitmapImageRep
object can have its raw pixel data inspected, can be put on the pasteboard, and can be encoded to any of the standard image formats that NSBitmapImageRep
supports (JPEG, TIFF, and so on.)
If you pass in a CIImage
object whose extents are not finite, this method raises an exception.
– initWithBitmapImageRep:
(CIImage)NSBitmapImageRep.h
Initializes a newly allocated NSBitmapImageRep
from the provided data.
- (id)initWithData:(NSData *)bitmapData
A data object containing image data. The contents of bitmapData can be any supported bitmap format. For TIFF data, the NSBitmapImageRep
is initialized from the first header and image data found in bitmapData.
Returns an initialized NSBitmapImageRep
if the initialization was successful or nil
if it was unable to interpret the contents of bitmapData.
NSBitmapImageRep.h
Initializes the receiver, a newly allocated NSBitmapImageRep
object, with bitmap data read from a rendered image.
- (id)initWithFocusedViewRect:(NSRect)rect
A rectangle that specifies an area of the current window in the current coordinate system.
Returns the initialized object or nil
If for any reason the new object can’t be initialized.
This method uses imaging operators to read the image data into a buffer; the object is then created from that data. The object is initialized with information about the image obtained from the window server.
NSBitmapImageRep.h
Returns YES
if image data is a planar configuration and NO
if its in a meshed configuration.
- (BOOL)isPlanar
In a planar configuration, the image data is segregated into a separate plane for each color and coverage component. In a meshed configuration, the data is integrated into a single plane.
NSBitmapImageRep.h
Returns the number of separate planes image data is organized into.
- (NSInteger)numberOfPlanes
This number is the number of samples per pixel if the data has a separate plane for each component (isPlanar
returns YES
) and 1 if the data is meshed (isPlanar
returns NO
).
– samplesPerPixel
– hasAlpha
(NSImageRep)– bitsPerSample
(NSImageRep)NSBitmapImageRep.h
Formats the receiver’s image data using the specified storage type and properties and returns it in a data object.
- (NSData *)representationUsingType:(NSBitmapImageFileType)storageType properties:(NSDictionary *)properties
An enum
constant specifying a file type for bitmap images. It can be NSBMPFileType
, NSGIFFileType
, NSJPEGFileType
, NSPNGFileType
, or NSTIFFFileType
.
A dictionary that contains key-value pairs specifying image properties. These string constants used as keys and the valid values are described in “Bitmap image properties.”
A data object containing the receiver’s image data in the specified format. You can write this data to a file or use it to create a new NSBitmapImageRep
object.
– TIFFRepresentation
– TIFFRepresentationUsingCompression:factor:
– TIFFRepresentation
(NSImage)– TIFFRepresentationUsingCompression:factor:
(NSImage)NSBitmapImageRep.h
Returns the number of components in the data.
- (NSInteger)samplesPerPixel
The returned value includes both color components and the coverage component, if present.
– hasAlpha
(NSImageRep)– bitsPerSample
(NSImageRep)NSBitmapImageRep.h
Changes the color of the pixel at the specified coordinates.
- (void)setColor:(NSColor *)color atX:(NSInteger)x y:(NSInteger)y
A color object representing the color to be set.
The x-axis coordinate of the pixel.
The y-axis coordinate of the pixel.
NSBitmapImageRep.h
Sets the receiver’s compression type and compression factor.
- (void)setCompression:(NSTIFFCompression)compression factor:(float)factor
An enum
constant that identifies one of the supported compression types as described in “Constants.”
A floating point value that is specific to the compression type. Many types of compression don’t support varying degrees of compression and thus ignore factor. JPEG compression allows a compression factor ranging from 0.0 to 1.0, with 0.0 being the lowest and 1.0 being the highest.
When an NSBitmapImageRep
is created, the instance stores the compression type and factor for the source data. TIFFRepresentation
and TIFFRepresentationOfImageRepsInArray:
(class method) try to use the stored compression type and factor. Use this method to change the compression type and factor.
NSBitmapImageRep.h
Sets the receiver's pixel at the specified coordinates to the specified raw pixel values.
- (void)setPixel:(NSUInteger[])pixelData atX:(NSInteger)x y:(NSInteger)y
An array of integers representing the raw pixel values. The values must be in an order appropriate to the receiver's bitmapFormat
. Small pixel sample values should be passed as an integer value. Floating point values should be cast int[]
.
The x-axis coordinate of the pixel.
The y-axis coordinate of the pixel.
NSBitmapImageRep.h
Sets the image’s property to value.
- (void)setProperty:(NSString *)property withValue:(id)value
A string constant used as a key for an image property. These properties are described in “Constants.”
A value specific to property
. If value is nil
, the value of the property is cleared.
The properties can affect how the image is read in and saved to file.
NSBitmapImageRep.h
Returns a TIFF representation of the receiver.
- (NSData *)TIFFRepresentation
This method invokes TIFFRepresentationUsingCompression:factor:
using the stored compression type and factor retrieved from the initial image data or changed using setCompression:factor:
. If the stored compression type isn’t supported for writing TIFF data (for example, NSTIFFCompressionNEXT
), the stored compression is changed to NSTIFFCompressionNone
before invoking TIFFRepresentationUsingCompression:factor:
. receiver, using the compression that’s returned by getCompression:factor:
(if applicable).
If a problem is encountered during generation of the TIFF, TIFFRepresentation
raises an NSTIFFException
or an NSBadBitmapParametersException
.
+ TIFFRepresentationOfImageRepsInArray:
– TIFFRepresentationUsingCompression:factor:
– representationUsingType:properties:
– TIFFRepresentation
(NSImage)– TIFFRepresentationUsingCompression:factor:
(NSImage)NSBitmapImageRep.h
Returns a TIFF representation of the image using the specified compression.
- (NSData *)TIFFRepresentationUsingCompression:(NSTIFFCompression)compression factor:(float)factor
An enum constant that represents a TIFF data-compression scheme. Legal values for compression can be found in NSBitmapImageRep.h
and are described in “Constants.”
A float
value that provides a hint for those compression types that implement variable compression ratios.
Currently only JPEG compression uses a compression factor. JPEG compression in TIFF files is not supported, and factor is ignored.
If the compression type isn’t supported for writing TIFF data (for example, NSTIFFCompressionNEXT
), the stored compression is changed to NSTIFFCompressionNone
before the TIFF representation is generated.
If a problem is encountered during generation of the TIFF, TIFFRepresentationUsingCompression:factor:
raises an NSTIFFException
or an NSBadBitmapParametersException
.
– canBeCompressedUsing:
+ TIFFRepresentationOfImageRepsInArray:
– TIFFRepresentation
– representationUsingType:properties:
– TIFFRepresentation
(NSImage)– TIFFRepresentationUsingCompression:factor:
(NSImage)NSBitmapImageRep.h
Returns the value for the specified property.
- (id)valueForProperty:(NSString *)property
A string constant used as a key for an image property. These properties are described in “Constants.”
A value specific to property
, or nil
if the property is not set for the bitmap.
Image properties can affect how an image is read in and saved to file. When retrieving the bitmap image properties defined in “Bitmap image properties,” be sure to check the return value of this method for a nil
value. If a particular value is not set for the image, this method may return nil
.
NSBitmapImageRep.h
These constants represent the various status values returned by incrementalLoadFromData:complete:
.
typedef enum { NSImageRepLoadStatusUnknownType = -1, NSImageRepLoadStatusReadingHeader = -2, NSImageRepLoadStatusWillNeedAllData = -3, NSImageRepLoadStatusInvalidData = -4, NSImageRepLoadStatusUnexpectedEOF = -5, NSImageRepLoadStatusCompleted = -6 } NSImageRepLoadStatus;
NSImageRepLoadStatusUnknownType
Not enough data to determine image format. You should continue to provide more data.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageRepLoadStatusReadingHeader
The image format is known, but not enough data has been read to determine the size, depth, etc., of the image. You should continue to provide more data.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageRepLoadStatusWillNeedAllData
Incremental loading cannot be supported. Until you call incrementalLoadFromData:complete:
with YES
, this status will be returned. You can continue to call the method but no decompression will take place. Once you do call the method with YES
, then the image will be decompressed and one of the final three status messages will be returned.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageRepLoadStatusInvalidData
An error occurred during image decompression. The image contains the portions of the data that have already been successfully decompressed, if any
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageRepLoadStatusUnexpectedEOF
incrementalLoadFromData:complete:
was called with YES
, but not enough data was available for decompression. The image contains the portions of the data that have already been successfully decompressed, if any.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageRepLoadStatusCompleted
Enough data has been provided to successfully decompress the image (regardless of the complete: flag).
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSBitmapImageRep.h
These constants identify properties that are used by representationOfImageRepsInArray:usingType:properties:
, representationUsingType:properties:
, setPixel:atX:y:
, and valueForProperty:
.
NSString *NSImageCompressionMethod; NSString *NSImageCompressionFactor; NSString *NSImageDitherTransparency; NSString *NSImageRGBColorTable; NSString *NSImageInterlaced; NSString *NSImageColorSyncProfileData; NSString *NSImageFrameCount; NSString *NSImageCurrentFrame; NSString *NSImageCurrentFrameDuration; NSString *NSImageLoopCount; NSString *NSImageGamma; NSString *NSImageProgressive; NSString *NSImageEXIFData; NSString* NSImageFallbackBackgroundColor
NSImageColorSyncProfileData
Identifies an NSData
object containing the ColorSync profile data.
It can be used for TIFF, JPEG, GIF, and PNG files. This value is set when reading in and used when writing out image data. You can get the profile data for a particular color space from the corresponding NSColorSpace
object or from the ColorSync Manager.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageCompressionFactor
Identifies an NSNumber
object containing the compression factor of the image.
Used only for JPEG files. JPEG compression in TIFF files is not supported, and the factor is ignored. The value is a float between 0.0 and 1.0, with 1.0 resulting in no compression and 0.0 resulting in the maximum compression possible. It’s set when reading in and used when writing out the image.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageCompressionMethod
Identifies an NSNumber
object identifying the compression method of the image.
Used only for TIFF files. The value corresponds to one of the NSTIFFCompression
constants, described below. It’s set when reading in and used when writing out.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageDitherTransparency
Identifies an NSNumber
object containing a boolean that indicates whether the image is dithered.
Used only when writing GIF files.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageInterlaced
Identifies an NSNumber
object containing a Boolean value that indicates whether the image is interlaced.
Used only when writing out PNG files.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageRGBColorTable
Identifies an NSData
object containing the RGB color table.
Used only for GIF files. It’s stored as packed RGB. It’s set when reading in and used when writing out.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSImageEXIFData
Identifies an NSDictionary
object containing the EXIF data for the image.
This property is used only when reading or writing JPEG files. The dictionary contains the EXIF keys and values. Th standard dictionary keys (that is, those that are not specific to camera vendors) are identical to those for kCGImagePropertyExifDictionary
declared in the CGImageSource
API. See kCGImagePropertyExifDictionary Keys
for details.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSImageFallbackBackgroundColor
Specifies the background color to use when writing to an image format (such as JPEG) that doesn't support alpha. The color's alpha value is ignored. The default background color, when this property is not specified, is white. The value of the property should be an NSColor
object. This constant corresponds to the kCGImageDestinationBackgroundColor
constant in Quartz.
Available in Mac OS X v10.5 and later.
Declared in NSBitmapImageRep.h
.
NSImageFrameCount
Identifies an NSNumber
object containing the number of frames in an animated GIF file.
This value is used when reading in data.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageGamma
Identifies an NSNumber
object containing the gamma value for the image.
Used only for PNG files. The gamma values is a floating-point number between 0.0 and 1.0, with 0.0 being black and 1.0 being the maximum color. It’s set when reading in and used when writing out.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSImageCurrentFrame
Identifies an NSNumber
object containing the current frame for an animated GIF file.
The first frame is 0.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageCurrentFrameDuration
Identifies an NSNumber
object containing the duration (in seconds) of the current frame for an animated GIF image.
The frame duration can be a floating-point value. It is used when reading in, but not when writing out.
Available in Mac OS X v10.2 and later.
Declared in NSBitmapImageRep.h
.
NSImageProgressive
Identifies an NSNumber
object containing a boolean that indicates whether the image uses progressive encoding.
Used only for JPEG files. It’s set when reading in and used when writing out.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSImageLoopCount
Identifies an NSNumber
object containing the number of loops to make when animating a GIF image.
A value of 0 indicates the animation should loop indefinitely. Values should be specified as integer numbers. It is used when reading in but not when writing out the image.
Available in Mac OS X v10.3 and later.
Declared in NSBitmapImageRep.h
.
When using the valueForProperty:
method to retrieve the the value for any of these keys, be sure to check that the returned value is non-nil
before you attempt to use it. A bitmap image representation may return nil
for any values that have not yet been set.
NSBitmapImageRep.h
The following file type constants are provided as a convenience by NSBitmapImageRep
:
typedef enum _NSBitmapImageFileType { NSTIFFFileType, NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, NSJPEG2000FileType } NSBitmapImageFileType;
NSTIFFFileType
Tagged Image File Format (TIFF)
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSBMPFileType
Windows bitmap image (BMP) format
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSGIFFileType
Graphics Image Format (GIF), originally created by CompuServe for online downloads
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSJPEGFileType
JPEG format
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSPNGFileType
Portable Network Graphics (PNG) format
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSJPEG2000FileType
JPEG 2000 file format.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSBitmapImageRep.h
These constants represent the various TIFF data-compression schemes supported by NSBitmapImageRep
.
typedef enum _NSTIFFCompression { NSTIFFCompressionNone = 1, NSTIFFCompressionCCITTFAX3 = 3, NSTIFFCompressionCCITTFAX4 = 4, NSTIFFCompressionLZW = 5, NSTIFFCompressionJPEG = 6, NSTIFFCompressionNEXT = 32766, NSTIFFCompressionPackBits = 32773, NSTIFFCompressionOldJPEG = 32865 } NSTIFFCompression;
NSTIFFCompressionNone
No compression.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionCCITTFAX3
CCITT Fax Group 3 compression.
Used for 1-bit fax images sent over telephone lines.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionCCITTFAX4
CCITT Fax Group 4 compression.
Used for 1-bit fax images sent over ISDN lines.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionLZW
LZW compression.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionJPEG
JPEG compression. No longer supported for input or output.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionNEXT
NeXT compressed. Used for input only.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionPackBits
PackBits compression.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSTIFFCompressionOldJPEG
Old JPEG compression. No longer supported for input or output.
Available in Mac OS X v10.0 and later.
Declared in NSBitmapImageRep.h
.
NSBitmapImageRep.h
These constants represent the various bitmap component formats supported by NSBitmapImageRep
. These values are combined using the C bitwise OR operator and passed to initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:
as the bitmap format and are returned by bitmapFormat
.
typedef enum { NSAlphaFirstBitmapFormat = 1 << 0, NSAlphaNonpremultipliedBitmapFormat = 1 << 1, NSFloatingPointSamplesBitmapFormat = 1 << 2 } NSBitmapFormat;
NSAlphaFirstBitmapFormat
If 0, alpha values are the last component.
For example, CMYKA and RGBA.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSAlphaNonpremultipliedBitmapFormat
If 0, alpha values are premultiplied.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSFloatingPointSamplesBitmapFormat
If 0, samples are integer values.
Available in Mac OS X v10.4 and later.
Declared in NSBitmapImageRep.h
.
NSBitmapImageRep.h
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)