Platforms to show: All Mac Windows Linux Cross-Platform

NSImageMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Cocoa Drawing MBS MacBase Plugin 7.2 ✅ Yes ❌ No ❌ No ✅ Yes All
An NSImage object is a high-level class for manipulating image data.
Example
// load an image file, convert it to a Xojo picture and save a PNG copy
Var file As FolderItem = SpecialFolder.Desktop.Child("test.jpg")
Var image As New NSImageMBS(file)

If Not image.isValid Then
MessageBox "Failed to load image."
Return
End If

MessageBox "Size: " + image.width.ToString + " x " + image.height.ToString

// as Xojo picture with alpha channel, e.g. to draw in a Canvas
Var pic As Picture = image.CopyPictureWithAlpha

// save as PNG
Var data As MemoryBlock = image.PNGRepresentation
Var output As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("test.png"), True)
output.Write data
output.Close

You use this class to load existing images or create new ones and composite them into a view or other image. This class works in conjunction with one or more image representation objects (subclasses of NSImageRep), which manage the actual image data.

All methods in this class will catch exceptions from Cocoa and raise a NSExceptionMBS instead. Using the message, name and reason properties you can see what was the reason for this exception. Please report if you find a method which does not handle exceptions correct.

Image Cache Modes

Constant Value Description
NSImageCacheAlways 1 Always generate a cache when drawing.
NSImageCacheBySize 2 Cache if cache size is smaller than the original data.
NSImageCacheDefault 0 Caching is unspecified.
Use the image rep's default.
NSImageCacheNever 3 Never cache; always draw direct.

Image Load Status

Constant Value Description
NSImageLoadStatusCancelled 1 Image loading was canceled.
The image contains the portions of the data that have already been successfully decompressed, if any.
NSImageLoadStatusCompleted 0 Enough data has been provided to completely decompress the image.
NSImageLoadStatusInvalidData 2 An error occurred during image decompression.
The image data is probably corrupt. The image contains the portions of the data that have already been successfully decompressed, if any.
NSImageLoadStatusReadError 4 Not enough data was available for full decompression of the image.
The image contains the portions of the data that have already been successfully decompressed, if any.
NSImageLoadStatusUnexpectedEOF 3 Not enough data was available for full decompression of the image.
The image contains the portions of the data that have already been successfully decompressed, if any.

This class has no subclasses.

Blog Entries

Xojo Developer Magazine

Videos

Release notes

Some useful global functions for this class:

Some methods using this class:

Some properties using this class:

Some events using this class:

Some examples using this class:

Some related classes:


The items on this page are in the following plugins: MBS MacBase Plugin.


NSImageCellMBS   -   NSImageRepMBS


The biggest plugin in space...