[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNUstep provides mechanisms for the retreival and display of images. A number of objects beginning with NSImage
(17) exist, each with slightly different functions.
An image is represented using an instance of the NSImage
class. You can create these using the path or URL of a file, raw image data or a pasteboard.
Images may contain zero or more image representations, or imagereps. For example, a photographic image may contain both black and white and colour representations, or representations at different resolutions. The purpose of this is to allow GNUstep to select the best representation for a particular device. GNUstep may select a lower-resolution representation for a screen, while selecting the highest resolution representation for printed output. If there was also a vector representation, it may choose to use it for printed output. An imagerep is represented by an instance of a NSImageRep
subclass.
An image by itself is not enough for rendering. Images are rendered on a window using an NSImageView
object. These let you set the alignment and scaling for displaying the image. They also let you set a graphical border using the -setFrameStyle:
method. NSImageView
is a control, so the normal control/cell model applies to it.
If you only need to display an image on it's own, use NSImageView
. For more complicated image rendering, e.g. inside of custom views, use NSImage
to draw or composite at a certain point.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Whether using NSImageView
or not, you will have to create an NSImage
object. It provides a number of constructors for loading an image with a path, a URL or a data object (NSData
). Note that for loading from a file or URL, two sets of methods are provided. These have subtly different meanings, as shown below:
-initWithContentsOfFile:
-initWithContentsOfURL:
-initByReferencingFile:
-initByReferencingURL:
From here, an image can be drawn within a view using any of the drawing/compositing/dissolving methods. You can also get at the imagereps using the -representations
method (amongst others).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
NSImage
provides a number of methods for drawing an image. It also provides quite a number means to control how an image is composited at its destination.(18) Compositing refers to the way the image is rendered onto the destination surface.
Simply drawing an image into your view may be achieved with the -drawRepresentation:inRect:
method. In other cases, you may wish to draw it onto a destination surface with a compositing operation, in which case you can use the -drawAtPoint:fromRect:operation:fraction:
or -drawInRect:fromRect:operation:fraction:
methods.
These take a rectangle from the source image, and composite it onto a destination surface. The compositing operation specifies how the image is blended with the destination surface, and is a constant in NSCompositingOperation
. These constants define what the destination image looks like after a composite, as a result of combining the source and destination image. (19)
NSCompositeClear
NSCompositeCopy
NSCompositeSourceOver
NSCompositeSourceIn
NSCompositeSourceOut
NSCompositeSourceAtop
NSCompositeDestinationOver
NSCompositeDestinationIn
NSCompositeDestinationOut
NSCompositeDestinationAtop
NSCompositeXOR
NSCompositePlusDarker
NSCompositePlusLighter
The fraction parameter corresponds to the coverage of the source alpha channel with zero making the source transparent and one making the source fully opaque.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Quite a number of classes inherit from NSImageRep
to provide means to load different types of image formats, such as bitmaps, TIFF images, etc:
NSBitmapImageRep
NSBitmapImageRep
is used. PNG, JPG and TIFF image file formats would be represented with the class.
You can retreive information about the image with methods such as -bitsPerPixel
or -isPlanar
. For image formats that can store metadata (such as resolution information or camera settings), the -valueForProperty:
and -setProperty:withValue:
methods can be used to manipulate it.
If necessary, it contains initialisers for instantiating it from raw data(-initWithData:
) and from the display (-initWithFocusedViewRect:
.
NSCachedImageRep
NSCustomImageRep
-draw
is called on the representation.
NSEPSImageRep
The NSImageRep
class itself also provides a number of methods for gaining information about what kinds of file formats GNUstep supports, and for instantiating images dynamically based on raw image data or the contents of a file or URL.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |