CGContextMBS shared methods

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGContextMBS class.

CGContextMBS.contextWithCGContext(handle as Integer) as CGContextMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CGContextMBS object based on a CGContextRef.
Example
// load a picture
dim f as FolderItem = SpecialFolder.Desktop.Child("ColorSpin.jpg")
dim pic as Picture = picture.Open(f)

// open printer
dim g as Graphics = OpenPrinterDialog
if g = nil then Return

// draw
g.DrawPicture pic, 0, 0

// now load again
dim ImageSource as new CGImageSourceMBS(f)
dim img as CGImageMBS = ImageSource.CreateImageAtIndex(0)
dim cs as CGColorSpaceMBS = CGColorSpaceMBS.CreateDeviceRGB

// copy with replacing colorspace
img = img.CopyWithColorSpace(cs)

// and draw
#If XojoVersion >= 2019.02 Then
Dim p As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(p)
#Else
Dim h As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(h)
#EndIf
dim r as CGRectMBS = CGMakeRectMBS(0, 0, img.Width, img.Height)

c.DrawPicture(img, r)
c.Flush

The CGContext is retained.
Returns nil on any error.

See also:

Some examples using this method:

CGContextMBS.contextWithCGContext(handle as Ptr) as CGContextMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CGContextMBS object based on a CGContextRef.
Example
// load a picture
dim f as FolderItem = SpecialFolder.Desktop.Child("ColorSpin.jpg")
dim pic as Picture = picture.Open(f)

// open printer
dim g as Graphics = OpenPrinterDialog
if g = nil then Return

// draw
g.DrawPicture pic, 0, 0

// now load again
dim ImageSource as new CGImageSourceMBS(f)
dim img as CGImageMBS = ImageSource.CreateImageAtIndex(0)
dim cs as CGColorSpaceMBS = CGColorSpaceMBS.CreateDeviceRGB

// copy with replacing colorspace
img = img.CopyWithColorSpace(cs)

// and draw
#If XojoVersion >= 2019.02 Then
Dim p As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(p)
#Else
Dim h As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(h)
#EndIf
dim r as CGRectMBS = CGMakeRectMBS(0, 0, img.Width, img.Height)

c.DrawPicture(img, r)
c.Flush

The CGContext is retained.
Returns nil on any error.

See also:

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


💬 Ask a question or report a problem