Platforms to show: All Mac Windows Linux Cross-Platform

NSGraphicsMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Cocoa Drawing MBS MacCocoa Plugin 7.7 ✅ Yes ❌ No ❌ No ✅ Yes All
The Cocoa class for drawing.
Example
// make new image
dim myImage as new NSImageMBS(500,500)
dim myGraphics as new NSGraphicsMBS(myImage)

// make logo image
dim myPicture as Picture = LogoMBS(500)
dim anotherImage as new NSImageMBS(myPicture)

// draw logo image to new image
myGraphics.drawInRect(anotherImage, 0, 0, myImage.width, myImage.height, 0, 0, anotherImage.width, anotherImage.height, myGraphics.NSCompositeSourceOver, 1.0)
myGraphics = nil // flush drawing

// save to file
dim f as FolderItem = SpecialFolder.Desktop.Child("test.jpg")
dim b as BinaryStream = BinaryStream.Create(f, True)
if b<>nil then
b.Write myImage.JPEGRepresentation
b.Close
end if

The plugin often provides in events such objects for drawing. In that case please only use the object in the event and don't store it for later use. It is only valid with in a draw event.

Internally this is a NSGraphicsContext object.

If you create objects on your own, make sure you only use the methods while the object is valid.

Constants

Constant Value Description
NSCompositeClear 0 Transparent. (R = 0)
NSCompositeCopy 1 Source image. (R = S)
NSCompositeDestinationAtop 9 Destination image wherever both images are opaque, source image wherever source image is opaque but destination image is transparent, and transparent elsewhere. (R = S*(1 - Da) + D*Sa)
NSCompositeDestinationIn 7 Destination image wherever both images are opaque, and transparent elsewhere. (R = D*Sa)
NSCompositeDestinationOut 8 Destination image wherever destination image is opaque but source image is transparent, and transparent elsewhere. (R = D*(1 - Sa))
NSCompositeDestinationOver 6 Destination image wherever destination image is opaque, and source image elsewhere. (R = S*(1 - Da) + D)
NSCompositeHighlight 12 Source image wherever source image is opaque, and destination image elsewhere. (Deprecated. Mapped to NSCompositeSourceOver.)
NSCompositePlusDarker 11 Sum of source and destination images, with color values approaching 0 as a limit. (R = MAX(0, (1 - D) + (1 - S)))
NSCompositePlusLighter 13 Sum of source and destination images, with color values approaching 1 as a limit. (R = MIN(1, S + D))
NSCompositeSourceAtop 5 Source image wherever both images are opaque, destination image wherever destination image is opaque but source image is transparent, and transparent elsewhere. (R = S*Da + D*(1 - Sa))
NSCompositeSourceIn 3 Source image wherever both images are opaque, and transparent elsewhere. (R = S*Da)
NSCompositeSourceOut 4 Source image wherever source image is opaque but destination image is transparent, and transparent elsewhere. (R = S*(1 - Da))
NSCompositeSourceOver 2 Source image wherever source image is opaque, and destination image elsewhere. (R = S + D*(1 - Sa))
NSCompositeXOR 10 Exclusive OR of source and destination images. (R = S*(1 - Da) + D*(1 - Sa)) Works only with black and white images and is not recommended for color contexts.
NSImageInterpolationDefault 0 One of the interpolation contants. Use the context's default interpolation.
NSImageInterpolationHigh 3 One of the interpolation contants. Slower, higher-quality interpolation.
NSImageInterpolationLow 2 One of the interpolation contants. Fast, low-quality interpolation.
NSImageInterpolationMedium 4 One of the interpolation contants. Medium quality, slower than NSImageInterpolationLow.
Available in Mac OS X v10.6 and later.
NSImageInterpolationNone 1 One of the interpolation contants. No interpolation.

Drawing Option Constants

Constant Value Description
NSStringDrawingDisableScreenFontSubstitution 4 Disable screen font substitution (equivalent to NSLayoutManager.setUsesScreenFonts(false)).
NSStringDrawingOneShot 16 Suppresses caching layout information.
NSStringDrawingTruncatesLastVisibleLine 32 Truncates and adds the ellipsis character to the last visible line if the text doesn't fit into the bounds specified. more
NSStringDrawingUsesDeviceMetrics 8 Uses image glyph bounds instead of typographic bounds.
NSStringDrawingUsesFontLeading 2 Uses the font leading for calculating line heights.
NSStringDrawingUsesLineFragmentOrigin 1 The specified origin is the line fragment origin, not the baseline origin.
Example

This class has no sub classes.

Some methods using this class:

Some events using this class:

Some examples using this class:

Blog Entries

Xojo Developer Magazine

Release notes

  • Version 20.0
    • Added CGContextMBS.contextWithCGContext and NSGraphicsMBS.graphicsContextWithCGContextHandle taking ptr for better coding in Xojo 2019r2 and newer.

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


NSFontPanelMBS   -   NSGroupTouchBarItemMBS


The biggest plugin in space...