Cocoa’s NSImage Class

In the previous example, we used an NSImageView object to display an image in our About box. The NSImageView class actually calls on another class, NSImage, to do its work. NSImage is the workhorse class for all images within the Cocoa development environment.

Cocoa uses objects of the NSImage class to display practically any kind of image on the screen. In Cocoa Version 10.1, the NSImage class could handle all the following types of images, and more:

  • Portable Document Format (PDF)

  • Tagged Image File Format (TIFF)

  • Windows Bitmap Format (BMP)

  • Graphics Interchange Format (GIF)

  • Joint Photographic Experts Group format ( JPEG)

  • Macintosh Picture format (PICT)

  • Untagged (raw) bitmap data

The NSImage class can also be extended on the fly by other programs that “register” themselves as filter services .[18] Because your programs will use the NSImage class, they too will be able to read images in any of these formats — without any additional work on your part.

[18] We’ll discuss Cocoa services in Chapter 20, but we won’t implement a filter service. For more information on filter services, please consult the NSImage documentation.

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.