Platforms to show: All Mac Windows Linux Cross-Platform

CGContextMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class CoreGraphics MBS MacCG Plugin 2.7 ✅ Yes ❌ No ❌ No ✅ Yes All
A class for a core graphics context.
Example
Dim p As New Picture(200, 200)
Dim g As Graphics = p.Graphics

// Clear image with white
g.ForeColor = &cFFFFFF
g.FillRect 0, 0, g.Width, g.Height

Dim c As New CGContextMBS(g)

c.SetRGBFillColor(1, 0, 0)

// coordinates are swapped in CGContext, so y = 20 means 20 pixels from bottom of picture!

Const x = 10
Const y = 20
Const w = 120
Const h = 100

c.FillRect New CGRectMBS(x, y, w, h)

Self.Backdrop = p

If the handle property has a non zero value, the destructor of this class will release the context reference.

If you create this in a method based on a window, please release it within that method. e.g. in a paint event, create it and let RB delete the last reference on the end of the method. Else you may see crashes as the context is still being around while the graphics port has been released.

Sub classes:

Some useful global functions for this class:

Some methods using this class:

Some properties using for this class:

Some events using this class:

Some examples using this class:

Blog Entries

Xojo Developer Magazine

Release notes

  • Version 20.3
    • Added new constructor for CGContextMBS class accepting graphics object.
  • Version 20.0
    • Added CGContextMBS.contextWithCGContext and NSGraphicsMBS.graphicsContextWithCGContextHandle taking ptr for better coding in Xojo 2019r2 and newer.
  • Version 18.4

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


CGColorSpaceMBS   -   CGDataConsumerMBS


The biggest plugin in space...